Showing posts with label powershell. Show all posts
Showing posts with label powershell. Show all posts

Wednesday, April 23, 2014

PowerShell - Correctly setting TrustedHosts

Hi guys

PowerShell has become such a valuable tool for administrators, that I myself am getting way too lazy to even think about opening RDP sessions to my servers. An extremely important function (obviously) is to be able to execute commands on remote machines; however you might run into trouble (especially when specifying the remote machine by IP) with default authentication issues:


Enter-PSSession : Connecting to remote server failed with the following error message : The WinRM client cannot process the request. Default authentication may be used with an IP address under the following conditions: the transport is HTTPS or the destination is in the TrustedHosts list, and explicit credentials are provided. Use winrm.cmd to configure TrustedHosts. Note that computers in the TrustedHosts list might not be authenticated. For more information on how to se
t TrustedHosts run the following command: winrm help config. For more information, see the about_Remote_Troubleshooting Help topic.

To quickly configure TrustedHosts on your client, simply run the following command on the client machine (through a console with elevated privileges):



Set-Item wsman:\localhost\Client\TrustedHosts <yourservernameorip> -Concatenate -Force
Bob's your uncle!
Now go ahead and run your beloved 'Enter-PSSession' command again!
Be happy, life is good :)
Hermann

Thursday, March 27, 2014

Control remote services with PowerShell

Dear Readers

Have you ever become so extremely lazy that you don't even want to use RDP to logon to your server so that you can start a service on it? It might just be me then, but either way PowerShell is just a great tool for remote admin.

In order to start a service on a remote machine:

get-service -displayname *<partofservicedisplayname>* -computername <machine> | set-service -status "Running"

Obviously you can stop a service similary by setting the status to "Stopped". Please note that you can also use parameters like -name (name of service).

Also please note that the "start-service" cmdlet will try to start the service on your local machine. The set-service cmdlet seemed to have done the trick for me.


Enjoy!


Hermann