Running:
Import-Module PowerShellGet
Gives the following error:
The file was skipped because of the following validation exception: File C:\program files\powershell\7\Modules\PackageManagement\PackageManagement.format.ps1xml cannot be loaded because its operation is blocked by software restriction policies, such as those created by using Group Policy..
Running:
Get-ExecutionPolicy -List
will display LocalMachine as RemoteSigned
Any suggestions to get the code to run with correct execution policy?
Your PowerShell Execution Policy might be preventing Import-Module
from running successfully. Try running:
Set-ExecutionPolicy -ExecutionPolicy AllSigned -Scope Process
This will allow all signed scripts to run in the current PowerShell process. When you close the PowerShell session, you will revert to your previous Execution Policy.
If the module is still not successfully importing, you might try:
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process
Be cautious about this setting, since it will allow any unsigned scripts to run, including potentially malicious code. Ensure that you trust the script/modules you're installing if you choose ExecutionPolicy Bypass.
You should refer to the documentation here for more details: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy?view=powershell-7