Using the below code in a PowerShell window:
$User = 'testuser1'
$Password = 'Pa$$w0rd' | ConvertTo-SecureString -AsPlainText -Force
$Credential = New-Object PSCredential -ArgumentList $User, $Password
Start-Process powershell -Credential $Credential
This works fine, but the PowerShell instance is not in elevated administrator mode. I tried:
$Arguments = "Start-Process powershell -Verb -RunAs"
Start-Process powershell -Credential $Credential -ArgumentList $Arguments
This opens a PowerShell instance, but it closes immediately.
How can I stop the new, elevated PowerShell instance closing?