$pw= convertto-securestring "PASSWORD" -asplaintext –force
$pp = new-object -typename System.Management.Automation.PSCredential -argumentlist "DOMAIN\user",$pw
$script = "c:\pathtoscript.ps1"
Start-Process powershell -Credential $pp -ArgumentList '-noprofile -command &{Start-Process $script -verb runas}'
Alternatively you can store the credential password in an encrypted file by doing this first, typing in the password, and pressing enter:
read-host -assecurestring | convertfrom-securestring | out-file C:\myencryptedfile.txt
And then the script would look like this:
$pw= get-content C:\myencryptedfile.txt | convertto-securestring
$pp=new-object -typename System.Management.Automation.PSCredential -argumentlist "DOMAIN\user",$pw
$script = "c:\pathtoscript.ps1"
Start-Process powershell -Credential $pp -ArgumentList '-noprofile -command &{Start-Process $script -verb runas}'
Passing the $script as a parameter to this should be easy enough and now you have a master script that can run anything just as if you had run Powershell as Administrator. (This assumes that credential username has administrative privileges)
original source