Techibee.com

Connect to remote powershell with alternate credentials

In my previous post, I talked about how to enable remoting feature and testing the connection. While playing with options of remote execution of commands, I felt why should I always use a powershell window which is opened with credentials that has admin rights on remote machine. I know the admin password of remote machine and started to look for the procedure where I can make use of it and execute remote commands. Finally ended with below procedure.

I know the local administrator password of compB and I have a powershell session opened on CompA with normal rights. I used the below steps to establish a connection and execute commands.

establishing connection…

[PS] C:> $remote = New-Pssession -ComputerName CompB -Credential administrator

Executing above, prompts for password of administrator account on CompB, so please do that to proceed.

Once the connection is established, you can issue commands using the established session like shown below

[PS] C:>invoke-command $remote {Get-Process}

This displays the process of remote machine.

Once you are done with you operation, you may choose to kill that session issuing below command

[PS]C:>remove-PsSession $remote

That’s it. Enjoy remote execution…

Happy Learning..,
Sitaram Pamarthi

Exit mobile version