Run PS with different user credentials

by neil4933 at 2012-11-17 10:44:06

Hi

I have a Powershell v2 script that I use to do various things. When I run the script from my admin machine, it obviously runs under the account that I am logged in as.

This was fine, but recently I have a requirement where I need to run the script using the account FABRIKAM\ADMIN1. Basically, what I’d like is for the script to run under that account and the person running the script is prompted to enter the password before the script actually runs. Is this possible?
by Makovec at 2012-11-18 07:20:58
Hi,

You can use #PSTip from PowerShellMagazine: http://www.powershellmagazine.com/2012/11/09/pstip-start-powershell-as-a-different-user-with-elevated-privileges/

Instead of running command (with -command parameter), you can use -File param to run script. See powershell /? for usage.

David
by vandreytrindade at 2012-11-26 06:03:17
Hi neil4933,

I’ve managed to make it work by using the command-lines below:

$ADcred = Get-Credential ("$env:USERDOMAIN$env:USERNAME$")
Start-Process powershell.exe -Credential $ADcred -ArgumentList "-File Change_password_code.ps1" -Wait

In my case the administrative account has a "$" in the end.
If you want to know for what I’m using this…
Check it out:
viewtopic.php?f=9&t=794

Hope it helps