This is a slight enhancement to Andy's answer to this question. If an admin sets a restrictive PowerShell script execution policy in a GPO (probably under the mistaken notion that PowerShell execution policy is a security boundary), you can get a PowerShell interactive session that has execution policy disabled by using the following command line:
powershell.exe -EncodedCommand ZgB1AG4AYwB0AGkAbwBuACAARABpAHMAYQBiAGwAZQAtAEUAeABlAGMAdQB0AGkAbwBuAFAAbwBsAGkAYwB5AHsAKAAkAGMAdAB4AD0AJABFAHgAZQBjAHUAdABpAG8AbgBDAG8AbgB0AGUAeAB0AC4ARwBlAHQAVAB5AHAAZQAoACkALgBHAGUAdABGAGkAZQBsAGQAKAAiAF8AYwBvAG4AdABlAHgAdAAiACwAIgBuAG8AbgBwAHUAYgBsAGkAYwAsAGkAbgBzAHQAYQBuAGMAZQAiACkALgBHAGUAdABWAGEAbAB1AGUAKAAkAEUAeABlAGMAdQB0AGkAbwBuAEMAbwBuAHQAZQB4AHQAKQApAC4ARwBlAHQAVAB5AHAAZQAoACkALgBHAGUAdABGAGkAZQBsAGQAKAAiAF8AYQB1AHQAaABvAHIAaQB6AGEAdABpAG8AbgBNAGEAbgBhAGcAZQByACIALAAiAG4AbwBuAHAAdQBiAGwAaQBjACwAaQBuAHMAdABhAG4AYwBlACIAKQAuAFMAZQB0AFYAYQBsAHUAZQAoACQAYwB0AHgALAAoAE4AZQB3AC0ATwBiAGoAZQBjAHQAIABNAGEAbgBhAGcAZQBtAGUAbgB0AC4AQQB1AHQAbwBtAGEAdABpAG8AbgAuAEEAdQB0AGgAbwByAGkAegBhAHQAaQBvAG4ATQBhAG4AYQBnAGUAcgAgACIATQBpAGMAcgBvAHMAbwBmAHQALgBQAG8AdwBlAHIAUwBoAGUAbABsACIAKQApAH0AOwBEAGkAcwBhAGIAbABlAC0ARQB4AGUAYwB1AHQAaQBvAG4AUABvAGwAaQBjAHkAOwBpAGYAKABUAGUAcwB0AC0AUABhAHQAaAAgACQAUABSAE8ARgBJAEwARQApAHsALgAgACQAUABSAE8ARgBJAEwARQB9AA== -NoExit
The -EncodedCommand
here is the following code:
function Disable-ExecutionPolicy{($ctx=$ExecutionContext.GetType().GetField("_context","nonpublic,instance").GetValue($ExecutionContext)).GetType().GetField("_authorizationManager","nonpublic,instance").SetValue($ctx,(New-Object Management.Automation.AuthorizationManager "Microsoft.PowerShell"))};Disable-ExecutionPolicy;if(Test-Path $PROFILE){. $PROFILE}
That is, disable the execution policy by running the function described in Andy's answer, and then dot-source the current user profile script if it exists.