none
Powershell to start another script with elevated credentials RRS feed

  • General discussion

  • I am trying to run a script to run another script with elevated credentials so I can install chocolatey
    I am having to do this through an agent.  I know not ideal but it is what I have to work with.
    This is to be run on multiple environments domain and non domain. I have the same local account on all computers.

    not sure if i'm asking for the domain correctly since its the local admin account not domain.

    $Username = '.\user'
    $Password = 'Password'
    $pass = ConvertTo-SecureString -AsPlainText $Password -Force
    
    $SecureString = $pass
    $MySecureCreds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Username,$SecureString 
    
    Start-Process powershell -Credential $credential -File C:\Temp\choco_install.ps1








    • Changed type Bill_Stewart Thursday, September 5, 2019 9:48 PM
    • Moved by Bill_Stewart Thursday, September 5, 2019 9:48 PM No - you cannot bypass the UAC prompt
    Thursday, July 25, 2019 2:37 PM

All replies

  • What is the issue or question?

    Note that there is no way to bypass the UAE prompt.


    \_(ツ)_/

    Thursday, July 25, 2019 2:58 PM
  • Ok so there is no way to silently run a script on a pc from another script with admin rights without user interaction?

    Thursday, July 25, 2019 3:55 PM
  • Ok so there is no way to silently run a script on a pc from another script with admin rights without user interaction?

    Task scheduler.

    Any interactive session requires UAE prompt. The scheduler doesn't and you can use the credentials to run the task. This saves exposing the password.


    \_(ツ)_/

    Thursday, July 25, 2019 3:59 PM
  • Can I set TS to run a script on a PC non domain and from another script?

    I would have to use an RMM agent to complete all my tasks.  
    If I have to touch the PC its not practical.  

    Thursday, July 25, 2019 4:38 PM
  • Can I set TS to run a script on a PC non domain and from another script?

    I would have to use an RMM agent to complete all my tasks.  
    If I have to touch the PC its not practical.  

    Why would you think that?

    I think you need to learn how to use the task scheduler.  There is no need for two scripts.  Just run one under the TS.


    \_(ツ)_/

    Thursday, July 25, 2019 5:26 PM
  • This is such a common question that we created a "sticky" post for it. It's right at the top of the forum. Please read this first:

    You cannot bypass the UAC prompt


    -- Bill Stewart [Bill_Stewart]

    Thursday, July 25, 2019 5:40 PM