There are multiple ways to execute a script in PowerShell. You can directly execute a PowerShell script in PowerShell terminal or command prompt. If you are using PowerShell core, then you can even execute a PowerShell script in your Linux terminal. You need to have proper execution policy set in order to execute the PowerShell script. Below is a quick reference –
Check current execution policy and set execution policy accordingly.
1 2 3 4 5 6 7 8 |
## Get the current execution policy Get-ExecutionPolicy ## Set execution policy to ByPass Set-ExecutionPolicy ByPass -Scope CurrentUser ## Or you can even set execution policy for a specific script powershell -ExecutionPolicy Bypass -File script.ps1 |
Execute PowerShell script from PowerShell terminal