PowerShell to remote host
If you have ever needed to remotely access a machine using the powerful CLI of PowerShell, it’s a very simple task and the syntax is pretty easy to remember as well which is nice. If you are wondering why you would want to powershell to remote host, here’s a couple scenarios:
1. Setting up a Hyper-V core machine since there’s no GUI and everything is managed from PowerShell.
2. You need to test some scripts on a remote server or workstation that you have credentials to.
3. Configure a remote system without disturbing it’s busy user.
Below are two examples on remotely connecting:
If you are on a Domain and have correct rights with your current account use the following syntax:
If you are not on the same Domain or connecting to a machine that is in a Workgroup then use the following Syntax:
Enter-PSSession –ComputerName Server Name –Credential Domain\UserName
If the machine is on a Workgroup and you want to use a local account change:
Domain\UserName to localhost\UserName
The word “localhost” can also be replaced by the actual hostname of the remove machine like:
this could then attempt to connect to the machine named CPU123 as the local user account as the Administrator. Next you should get a popup window prompting for that users password. Once entered then your PowerShell prompt will become a remote shell to the other Host you just specified. This is very similar to SSHing to a remote Linux Box. Now to confirm where your prompt resides just run:
this will return the name of the host that the prompt is on.
I have had scenarios in which the local Administrator account has been disabled and that either the user(s) had Administrative rights or that another account within that Domain was designated as the Administrator account for security reasons.
Lastly, once you are done doing whatever testing or administrative tasks that you needed to do you can disconnect the remote shell by typing the following command:
Please like, share and subscribe if you found this article useful.