Q: How can I create a PowerShell session to a remote machine as a different user?
A: There are several ways to create a PowerShell session to a remote machine as a different user. The following code requests the credentials you want to use and then creates and connects remotely to the machine where you can run commands:
$cred=Get-Credential $sess = New-PSSession -Credential $cred -ComputerName <remote machine> Enter-PSSession $sess <Run commands in remote session> Exit-PSSession Remove-PSSession $sess
When you're finished, type Exit-PSSession and then remove the session.