Running Microsoft PowerShell in unrestricted mode

Came across this a while back. I tried to run some commands from Microsoft PowerShell, but got an error message:

Import-Module : There were errors in loading the format data file: Microsoft.PowerShell, , C:\Users\Administrator\AppData\Local\Temp\2\tmp_53559126-b068-417a-b9f3-c7ffd1a7304e_fq4thsik.mpj\tmp_53559126-b068-417a-b9f3-c7ffd1a7304e_fq4thsik.mpj.format.ps1xml : File skipped because of the following validation exception: File C:\Users\Administrator\AppData\Local\Temp\2\tmp_53559126-b068-417a-b9f3-c7ffd1a7304e_fq4thsik.mpj\tmp_53559126-b068-417a-b9f3-c7ffd1a7304e_fq4thsik.mpj.format.ps1xml cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details
..
At line:3 char:30 + Import-Module <<<< -Name $name -Alias * -Function * -Prefix $prefix -DisableNameChecking:$disableNameChecking -PassThru -ArgumentList @($session) + CategoryInfo : InvalidOperation: (:) [Import-Module], RuntimeException + FullyQualifiedErrorId : FormatXmlUpateException,Microsoft.PowerShell.Commands.ImportModuleCommand

At that time, i wan’t too worried as i had another way of achieving what i needed, but this time there was no other way, so i had to look in to it properly.  Eventually discovered that by default to prevent malicious use, scripting is disabled by default. Yes i know, you wonder as well why to have a powerful shell if it has scripting disabled.

Anyway,  found the quick solution, thanx to this Microsoft Technet Article. Long story short, to check scripting status, run:

> Get-ExecutionPolicy

You might want to make not of the status of the original ExecutionPolicy. Than to change the status, you can run:

> Set-ExecutionPolicy Unrestricted

Finally, once you are finished with the tasks/scripts and you won’t need this feature in the forseable future, you can change the setting back to it’s original status by running the Set-ExecutionPolicy command again.

 

In category: Microsoft PowerShell
Tagged with: