
How to execute PowerShell scripts
If you have never ran a PS script on your computer, probably the default policy denies the execution. To allow scripts execution chose any option from below list which best fits for you. First start the PowerShell console with admin rights.
- Set-ExecutionPolicy – this command changes the default policy:
Set-ExecutionPolicy Bypass
Check the Microsoft’s article for more info: About Execution Policies - Unblock-File – the Cmdlet is available since PowerShell version 3.0.
Unblock-File -Path C:\MyScript.ps1 - Modify Data Stream – works for all file types.
- Clear file stream preferences:
cmd /c echo.> C:\MyScript.ps1:Zone.Identifier - Edit file stream preferences in notepad:
notepad C:\MyScript.ps1:Zone.Identifier
- Clear file stream preferences:
- Execute script as string – If PS script execution is disabled on the system and you are not allowed to modify the policy, below command reads the file as a single line string, converts the content to a script block and execute it by call operator ‘&’
& ([ScriptBlock]::Create((Get-Content C:\MyScript.ps1 | Out-String)))