Search

"Run with PowerShell" feature doesn't work on Windows 7 by Aleksandar Nikolić

Active

3
0
Sign in
to vote
Type: Bug
ID: 775161
Opened: 12/26/2012 4:11:35 PM
Access Restriction: Public
1
Workaround(s)
1
User(s) can reproduce this bug
"Run with PowerShell" feature runs as expected on Windows 8 computer. If we compare Registry value that defines a command that runs when we select "Run with PowerShell" on a contextual menu, we can see that commands are quite different. Why it fails on Windows 7 (and probably Server 2008/2008 R2; I haven't tested that)? -File and -Command parameters cannot be used in the same command.

On Windows 8:
C:\PS> Get-ItemProperty REGISTRY::HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\0\Command | Select -Expand "(default)"

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -Command "if((Get-ExecutionPolicy ) -ne 'AllSigned'){ Set-ExecutionPolicy -Scope Process Bypass }; & '%1' %*

On Windows 7:
PS C:\> Get-ItemProperty REGISTRY::HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\0\Command | Select -Expand "(default)"

"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" "-file" "%1" "-Command" "if((Get-ExecutionPolicy ) -ne AllSigned) { Set-ExecutionPolicy -Scope Process Bypass }"
Details (expand)
How often does this happen?
Always Happens

Have you seen this problem before in this product?

No, this is new to the most recent version
Reproduction Steps
 
Expected Results
 
File Attachments
0 attachments
Sign in to post a comment.
Sign in to post a workaround.
Posted by Rohn Edwards on 2/7/2013 at 8:58 AM
If you can't change the command that the context menu runs to match what Windows 8 uses, and you still want to be able to use the context menu, you can create an optional parameter called 'Command' in the script file. This will catch the -Command argument being passed to powershell.exe (it should contain the string 'if((Get-ExecutionPolicy ) -ne AllSigned) { Set-ExecutionPolicy -Scope Process Bypass }').