09 February 2018

Run PowerShell as Administrator One-Liner

As you have probably seen recently in my latest blog entries, I am working on a bunch of PowerShell one-liners to do away with the actual scripts and be able to implement the PowerShell process as a command line task sequence.

This one-liner will add the necessary registry entry to allow for a user to run a PowerShell script as administrator. This has been tested in a task sequence.

Here is the command line:

powershell.exe -command "&{$Key='REGISTRY::HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\runas'; New-Item -path $Key -Name 'Command' -Value '(Default)' -force; New-ItemProperty -Path $Key'\Command' -Name '(Default)' -Value '""c:\windows\system32\windowspowershell\v1.0\powershell.exe""" -noexit """%1"""' -force}"



0 comments:

Post a Comment