Run PowerShell ISE as Administrator under different credentials

I came to post this on my blog digging various alternates to loop through and run the powershell script for deployment, activation of feature, etc to run under a farm administrator… finally i made through getting through … Here is the code that launches the powershell ISE to under the farm account

# Farm account name
$farmAccountname = “domain\farm_account”

# Load the Farm Account Credential
$cred = Get-Credential $farmAccountname

# Create a new process with UAC elevation
Start-Process $PsHome\powershell.exe -Credential $cred -ArgumentList “-Command Start-Process $PSHOME\powershell_ise.exe -Verb Runas” -Wait

This will then pop the username window. Type in the username and password (farm admin) . Hitting ok will get you to the Powershell ISE window which will run with the desierd credentials you provide.

To verify which account it run (which will eventually get the username you provided)

[Security.Principal.WindowsIdentity]::GetCurrent().Name

Leave a Reply

Your email address will not be published. Required fields are marked *

Bitnami