Changing the execution policy
Published on: 2nd Nov 2019
Updated on: 16th Jan 2022
Explanation
By default, running any PowerShell script file has been forbidden and the following error will appear on the screen:
File D:\temp5\test.ps1 cannot be loaded because running scripts is disabled on this system. For
more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170. + CategoryInfo : SecurityError: ( : ) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : UnauthorizedAccess
To view the current settings, run the following command:
Get-ExecutionPolicy -List
To be able to execute .ps1 file using Powershell console or ISE, run the following command:
Set-ExecutionPolicy RemoteSigned
To learn more about RemoteSigned, visit the following page:
On the other hand, to execute the commands in a .ps1 file from any C# program, then, you don't need this.
Jump to #POWERSHELL blog
Author
Lau Hon Wan, software developer.