In this post I will be sharing my experiences with power shell remote capabilities.okay lets move on.
Powershell remoting allows to run individual commands or to access full powershell sessions on remote systems similar to SSH. Powershell remoting is disabled by default (well…obviously! :P) and needs to be enabled. this is easy on domain joined computers but a bit more complex on workgroups but hey! this aint rocket science!
Enabling Powershell remoting
Fire up an elevated powershell session. (Right Click and run as admin). and run the following cmdlet.
enable-psremoting –force
This will result in enabling WinRm service, setting it to start automatically with the system and creates a firewall rule for incoming connections. –force switch will enable these settings without prompting the user for each step. If the PCs are domain joined, this is all you have to do and you are good to go for remote powershelling.
Workgroup Settings
If the computers you need to do powershell remoting is in a work group, you need a few extra steps as given below.
First, run the enable-psremoting -force command on an elevated powershell on the computer you want to initiate connections from. So that both ends are now remote enabled!
Configure trustedhost settings on both computers so that they trust each other. The following command, for an example, trusts any computer and is suitable for a setup like a home network. you may replace the “*” with a comma separated list of computer names or IP addresses to restrict access.
Set-Item wsman:\localhost\client\trustedhosts *
on both computers.
Restart the WinRm service for the settings to take effect.
Restart-Service WinRm
Testing Connections
Run the following command on the computer your are connecting from to check what you did was successful. Replace COMPUTER with the name of the remote computer. The command will test if the winrm services is running successfully on the remote computer.
test-wsman COMPUTER
The successful completion of this command ensures WinRm is enabled and computers can connect.
Thats it!! lets run a few commands or start a remote powershell session!!
Run an individual command using invoke-command
invoke-command –computername COMPUTER –scriptblock {COMMAND} –credential USERNAME
Replace COMPUTER with the remote computer name or ip address, COMMAND with the command you want to run and USERNAME with the user name of the remote computer. The following screen cap shows get-host output on a remote computer.
Enabling a powershell session allows you to run multiple commands instead of a single command. You can initiate a remote powershell session using the following command.
enter-pssession –computername COMPUTER –credential USER
Replace COMPUTER and USER with the hostname of the remote computer and the username which you hope to log on with. type exit anytime you wish to log out of the remote session.
No comments:
Post a Comment