This post is part of the series on PowerShell for Hyper-V.
If you try to run a PowerShell script, you will receive an error:
File C:TempResume HVVMs.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
This is deliberate on Microsoft’s part to make sure a script is not inadvertently run. You can enable running of scripts, but this is very risky.
However, there is a command you can run which will, for only the script being run, allow the script to run (replace the highlighted section with your script file):
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File {your script}
The relevant section is
-ExecutionPolicy Bypass
which tells PowerShell that it may bypass the execution policy restriction.
Click to show/hide the PowerShell for Hyper-V Series Index
PowerShell for Hyper-V |
---|
Avoid Error Running PowerShell Scripts |
Start VM |
Shut Down VM |
Save VM |
Suspend VM |
Resume VM |
What should we write about next?
If there is a topic which fits the typical ones of this site, which you would like to see me write about, please use the form, below, to submit your idea.