# RunAs Command to Run a Script Under Alternate User Credentials

**URL:** <https://forums.powershell.org/t/runas-command-to-run-a-script-under-alternate-user-credentials/4882>\
**Category:** PowerShell Help\
**Created:** [September 15, 2015, 11:52am UTC](https://forums.powershell.org/t/runas-command-to-run-a-script-under-alternate-user-credentials/4882 "2015-09-15T11:52:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![imessage357\_h1](https://avatars.discourse-cdn.com/v4/letter/i/91b2a8/32.png) [@imessage357\_h1](https://forums.powershell.org/u/imessage357_h1)\
**Post date:** [September 15, 2015, 11:52am UTC](https://forums.powershell.org/t/runas-command-to-run-a-script-under-alternate-user-credentials/4882/1 "2015-09-15T11:52:22Z")

</div>

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:

@ECHO OFF  
SET ThisScriptsDirectory=%~dp0  
SET PowerShellScriptPath=%ThisScriptsDirectory%MyScript.ps1  
PowerShell -NoProfile -ExecutionPolicy Bypass -Command ‘Start-Process PowerShell -ArgumentList ‘-NoProfile -ExecutionPolicy Bypass -File “”%PowerShellScriptPath%“”’ -Verb RunAs’

thank again

---

<div class="post-metadata">

**Author:** ![imessage357\_h1](https://avatars.discourse-cdn.com/v4/letter/i/91b2a8/32.png) [@imessage357\_h1](https://forums.powershell.org/u/imessage357_h1)\
**Post date:** [September 15, 2015, 11:54am UTC](https://forums.powershell.org/t/runas-command-to-run-a-script-under-alternate-user-credentials/4882/2 "2015-09-15T11:54:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:44pm UTC](https://forums.powershell.org/t/runas-command-to-run-a-script-under-alternate-user-credentials/4882/3 "2024-05-16T20:44:47Z")

</div>


