PowerShell command prompt

Create Remote PowerShell Session As Different User

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.

TAGS: Windows 8
Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish