When I tried to setup Piwik auto archiving using Windows Scheduler to call a Powershell script, I got the following error “File archive.windows.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see “get-help about_signing” for more details.”. I googled so many times to find out how to fixed this issue.
And, the reason is the security settings built into Windows PowerShell include something called the “execution policy” the execution policy determines how (or if) PowerShell runs scripts. By default, PowerShell’s execution policy is set to Restricted. This setting means that you may not run any PS1 script at all.
You can verify the settings for your execution policy by typing the following at the PowerShell command prompt and then pressing ENTER:
[text] Get-ExecutionPolicy[/text]
If you’re working on a desktop and just experimenting with PowerShell, the best is to set the policy-level to Unrestricted. This allows you do everything with annoying security boundaries. Just be careful not to run every script you download from the internet. If you’re working in a production environment and only want to run self-written scripts, the RemoteSigned level should be loosy enough.
To change the Execution Policy to Unrestricted, type the following command in Powershell
[text] Set-ExecutionPolicy Unrestricted[/text]
To change the Execution Policy to RemoteSigned, type the following command in Powershell
[text] Set-ExecutionPolicy RemoteSigned[/text]
That’s all, after I run the command: Set-ExecutionPolicy Unrestricted, the Piwik auto archiving archive.windows.ps1 Powershell script which is using Windows Scheduler runs properly.