Welcome › Forums › General PowerShell Q&A › RunAs Command to Run a Script Under Alternate User Credentials
This topic contains 1 reply, has 1 voice, and was last updated by
I use a batch file to run a powershell script for my non-Tech co-workers.
I need to run this script with alt creds so it will install a piece of software.
I know its not best but I dont care if the password is in clear text in the script.
any help would be greatly appreciated!
hears my batch file to kick off the ps script:
PowerShell -NoProfile -ExecutionPolicy Bypass -Command 'Start-Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""%PowerShellScriptPath%""' -Verb RunAs'
I was looking to use this in my powershell script to use the alt creds
$Username = "PC01\user1"
$Password = 'P@ssword'
$PasswordSS = ConvertTo-SecureString -String $Password -AsPlainText -Force
$Creds = New-Object -Typename System.Management.Automation.PSCredential -Argumentlist $Username,$PasswordSS
Start-Process powershell.exe -Credential $Creds -NoNewWindow -ArgumentList "Start-Process powershell.exe -Verb runAs"
#enter code here
It does open a new admin window but executes the code in the cmd.exe that is opened by the batch file.
The topic ‘RunAs Command to Run a Script Under Alternate User Credentials’ is closed to new replies.