Ezine 202 PowerShell Remoting with TrustedHostsEzine 202 PowerShell Remoting with TrustedHostsThe ability to create a remote connection is the most important difference between PowerShell v 1.0 and 2.0. However, setting up remoting for the first time, is one of the most difficult tasks in PowerShell. But no worries, I will lead through the steps and anticipate some of the potential problems with WinRm and TrustedHosts. Topics for PowerShell 2.0 Remote Connection
♣ This Week's SecretPowerShell 1.0 is easier to learn than v 2.0, largely because there are few cmdlets and certainly no ability to create a remote session. However, for those who mastered the basics of v 1.0, this inability to run scripts against another machine soon becomes a severe limitation. Furthermore, once you have a working knowledge of PowerShell, then setting up remoting is not so hard after all. It's almost as though PowerShell 2.0 has this built in hurdle, you won't be able to use remoting until your good enough to find, and then control, the TrustedHosts configuration. This Week's Mission - To Enable Remoting in PowerShell v 2.0I have divided our mission into four sections, this breakdown is particularly handy for troubleshooting.
Goal - To Install the WinRm service and understand the corresponding WSMan namespace / provider. The problem in explaining how to install WinRm is that each operating system has a different requirement. Windows 7 and Windows Server 2008 R2 already have WinRm, so there is no need worry about installing this service. However, for Vista, XP and Windows Server 2008 you need to download the files from Microsoft and install WinRm. Any doubts on what your machine already has installed either check the Services mmc, or better still use PowerShell and try: get-Service winrm. Goal - To Enable PowerShell Remoting Launch PowerShell v 2.0 as an administrator then try this: Enable-PSRemoting Note that unlike PSSession commands, this function only has one 'S' - PSRemoting. Actually, the underling cmdlet is Enable-PSSessionConfiguration. Running Enable-PSRemoting cmdlet achieves the following: Starts the WinRM service and sets the startup type to Automatic. Enables a firewall exception for WS-Management communications. Creates a listener to accept requests on any IP address. Goal - To Check TrustedHosts for * (All) First let us digress and check for PowerShell 'providers'. Get-PsProvider The point of the other command is to show the existence of the WSMan namespace which maps to WinRm. Next we can check its config settings in general and TrustedHosts in particular. # PowerShell 2.0 Please note: cd wsman fails, we need that colon. Crucial Goal - Set TrustedHosts * Important, this will not work unless you are in the localhost\client folder of the WSMan namespace, see above instruction. # PowerShell 2.0 Note 1: For PowerShell to recognise the new TrustedHosts settings you need to restart the WinRm service. It's satisfying to use PowerShell itself to achieve this with restart-Service winrm Note 2: A rare plural. All the PowerShell cmdlets are singular, but TrustedHosts is plural. Note 3: If this command gives trouble, revert to DOS!
Run winrm -? in a CMD box As Administrator, specifically: Note 4: Once the euphoria of success wears off you may want to limit * and substitute the names of servers on your network. Final Goal - To Complete Our Mission and Create a PowerShell Remote Session # PowerShell 2.0 Enter-PSSession requires a fully.quallified.domain.name e.g. BigServer.domain.local Plain BigServer would NOT work, however the IP address is always good in this situation. Where Next?Once remoting is working then there is no barrier to employing PowerShell to manage network computers, you can now run scripts against other machines. Many cmdlets support the -computerName parameter, but remoting also enables you to use the PSSession family of cmdlets and also invoke-Command. WMI Monitor Details
| |||||
Custom Search
|
Guy Recommends: WMI Monitor and It's Free!
|
|
Home Copyright © 1999-2012 Computer Performance LTD All rights reserved Please report a broken link, or an error. | |