Home > PowerShell > Connect to remote powershell with alternate credentials

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 -Credentials aadministrator

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

  1. Carl Wayne
    April 21, 2011 at 3:05 am | #1

    none of this works! I have no idea what I am doing wrong. Please help!

  2. April 22, 2011 at 9:17 pm | #2

    Ensure that you have remoting enabled on remote computer that you are trying to connect. http://techibee.com/powershell/how-to-enable-remoting-in-powershell-v2/248

  1. No trackbacks yet.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>