powershell runas code example

Example 1: how to login to another user in powershell

$username = 'user'
$password = 'password'

$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential $username, $securePassword
Start-Process Notepad.exe -Credential $credential

Example 2: powershell script run

./myscript.ps1  //if is in the current directory
c:/scripts/myscript.ps1  //if you want to use the full path
&"C:/my path with space/myscript.ps1"  //if your path has spaces

Tags:

C Example