PowerShell for Hyper-V: Avoid Error Running PowerShell Scripts

Hyper-VThis post is part of the series on PowerShell for Hyper-V.

If you try to run a PowerShell script, you will receive an error:

PowerShell error trying to run script

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.

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.

Your Name

Your Email

Suggested Topic

Suggestion Details

Leave a Reply

Your email address will not be published. Required fields are marked *