Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 284 Vote(s) - 3.45 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to run a PowerShell script

#11
In case you want to run a PowerShell script with Windows Task Scheduler, please follow the steps below:

1. Create a task

2. Set `Program/Script` to `Powershell.exe`

3. Set `Arguments` to `-File "C:\xxx.ps1"`

It's from another answer, *https://stackoverflow.com/questions/23953926/how-to-execute-a-powershell-script-automatically-using-windows-task-scheduler/23954618#23954618*.


Reply

#12
Use the `-File` parameter in front of the filename. The quotes make PowerShell think it is a string of commands.

Reply

#13
If you are on PowerShell 2.0, use PowerShell.exe's `-File` parameter to invoke a script from another environment, like cmd.exe. For example:

Powershell.exe -File C:\my_path\yada_yada\run_import_script.ps1

Reply

#14
You can run from cmd like this:
```
type "script_path" | powershell.exe -c -
Reply

#15
With the appropriate execution policy, you should just be able to call the file directly and Windows will associate it with PowerShell
```
C:\my_path\yada_yada\run_import_script.ps1
```

That does not do so well with arguments. The real answer to your question is that you are missing the `&` to say "execute this"
```
powershell.exe '& C:\my_path\yada_yada\run_import_script.ps1'
```
Reply

#16
I've just found the method what Microsoft do when we right click on a `ps1` script and click on "Run with PowerShell" :

```
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" "-Command" "if((Get-ExecutionPolicy ) -ne 'AllSigned') { Set-ExecutionPolicy -Scope Process Bypass }; & 'C:\Users\USERNAME\Desktop\MYSCRIPT.ps1'"
```
Reply

#17
Prerequisites:

- You need to be able to run PowerShell as an administrator
- You need to set your PowerShell execution policy to a permissive value or be able to bypass it

Steps:

1. Launch Windows PowerShell as an Administrator, and wait for the `PS>` prompt to appear
2. Navigate within PowerShell to the directory where the script lives:

PS> cd C:\my_path\yada_yada\ (enter)

3. Execute the script:

PS> .\run_import_script.ps1 (enter)

Or: you can run the PowerShell script from the Command Prompt (`cmd.exe`) like this:

powershell -noexit "& ""C:\my_path\yada_yada\run_import_script.ps1""" (enter)

according to [*Invoking a PowerShell script from cmd.exe (or Start | Run)*][1] by Kirk Munro.

Or you could even [run your PowerShell script asynchronously from your C# application][2].

[1]:

[To see links please register here]

[2]:

[To see links please register here]


Reply

#18
1. Open PowerShell in administrator mode
2. Run: `set-executionpolicy unrestricted`
3. Open a regular PowerShell window and run your script.

I found this solution following the link that was given as part of the error message: *[About Execution Policies][1]*

Make sure to run `set-ExecutionPolicy default` once you're done, or you will be exposed to security risks.

[1]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through