Windows – Powershell Start-Process -Credential

command linepowershellwindows 7

I seem to have some issue with running elevated administration using powershell.

To be honest, im not that good with powershell.

So im running this script [powershell -command "Start-Process iexplore -Verb -RunAs"].

I understand that powershell Start-Process cmdlet has the parameter -Credential.

But when i do Get-Help Start-Process , it doesnt explain this parameter and google didnt bring me anywhere close.

Running -RunAs at the end calls my local admin instead of my AD admin ID , this is fine.

I would like to know how to actually insert my User ID/Password in the powershell Start-Process line.

Running RunAs within Command Prompt isnt going well, but i do know it is easier there with "/User:[user] password".

Best Answer

The -credential parameter is used like this:

-credential "ComputerNameOrIP\admin"

Examples:

-credential "192.168.1.1\admin\"

-credential "SomeComputerName\SomeUsername"

In the case of domain accounts, just use the domain name instead of computer name and it works just the same.

If you use this correctly, when started, it will spawn a logon screen where you just have to type the password and click OK.

You can store the password in an external file and then use it in the script.

 read-host -assecurestring | convertfrom-securestring | out-file C:\pass.txt

$password = get-content C:\pass.txt | convertto-securestring

$credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist "UserName",$password
Related Question