Start-Process -verb runas & -Credential RRS feed

  • Question

  • I want to be able to start a process in elevated mode and with another user credentials.

    I am logged on with a user that is a local administrator on a Windows 7 client.
    I now want to start a process in elevated mode but with other credentials that also is a local administrator & a domain administrator.

    I run the following command from Powershell command window.
    Start-Process -FilePath C:\Windows\notepad.exe -verb runas -Credential mydomain\mydomainAdminUser

    This will result in the following error:
    Start-Process : Parameter set cannot be resolved using the specified named parameters.
    At line:1 char:14
    + Start-Process <<<<  -FilePath C:\Windows\notepad.exe -verb runas -Credential mydomain\mydomainAdminUser
        + CategoryInfo          : InvalidArgument: (:) [Start-Process], ParameterBindingException
        + FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.Commands.StartProcessCommand

    If I run the command "Start-Process -FilePath C:\Windows\notepad.exe -verb runas" it will start notepad in elevated mode but with the loggon user credential.

    If I run the command "Start-Process -FilePath C:\Windows\notepad.exe -Credential mydomain\mydomainAdmin" it will start the process as my mydomainAdmin account but not in elevated mode.

    Any ideas?

    BR Pierre


    Working with Softgrid since 2002
    Thursday, March 31, 2011 10:39 AM


  •  Start-Process powershell -Credential mydomain\mydomainAdmin -ArgumentList '-noprofile -command &{Start-Process notepad -verb runas}'

    Thursday, March 31, 2011 12:00 PM

All replies

  •  Start-Process powershell -Credential mydomain\mydomainAdmin -ArgumentList '-noprofile -command &{Start-Process notepad -verb runas}'

    Thursday, March 31, 2011 12:00 PM
  • Thank you Mr Kazun.


    Back up my hard drive? How do I put it in reverse?
    Tuesday, April 5, 2011 11:57 AM
  • This is the best answer I have found on how to run Powershell scripts as an elevated user running under administrative credentials.   I spent all day scouring web sites on how to get here and only found bits and pieces of the puzzle.

    Here is the example that worked for me that puts all the pieces together

    $pw= convertto-securestring "PASSWORD" -asplaintext –force
    $pp = new-object -typename System.Management.Automation.PSCredential -argumentlist "DOMAIN\user",$pw
    $script = "c:\pathtoscript.ps1"
    Start-Process powershell -Credential $pp -ArgumentList '-noprofile -command &{Start-Process $script -verb runas}'

    Alternatively you can store the credential password in an encrypted file by doing this first, typing in the password, and pressing enter:

    read-host -assecurestring | convertfrom-securestring | out-file C:\myencryptedfile.txt 

    And then the script would look like this:

    $pw= get-content C:\myencryptedfile.txt | convertto-securestring
    $pp=new-object -typename System.Management.Automation.PSCredential -argumentlist "DOMAIN\user",$pw
    $script = "c:\pathtoscript.ps1"
    Start-Process powershell -Credential $pp -ArgumentList '-noprofile -command &{Start-Process $script -verb runas}'

    Passing the $script as a parameter to this should be easy enough and now you have a master script that can run anything just as if you had run Powershell as Administrator.  (This assumes that credential username has administrative privileges)


    Sunday, July 22, 2012 9:16 PM
  • Thanks a lot for the provided information. I was able to run elevated Powershell process, however I have a problem with setting a working directory for that elevated process. I want to set the working directory same as the script was run from.

    I've spent numerous hours on trying to pass an argument to the script block "{Start-Process $script -verb runas}" but no luck.

    Can this be achieved at all or I am trying to do something that's not possible?

    Thanks in advance for your assistance!

    Wednesday, August 3, 2016 8:05 PM
  • Hi,

    Did you succeed to set the working directory?



    Saturday, December 10, 2016 10:11 PM
  • Start-Process -FilePath PowerShell.exe -WorkingDirectory $env:UserProfile

    Friday, October 26, 2018 4:11 PM