Prof. Powershell

Get That Server

PowerShell 2.0 has the power to do more. But you gotta read the help to find out what works and what doesn't. Herewith, an example.

PowerShell 1.0 introduced us to some very handy cmdlets, like Get-Process and Get-Service. Unfortunately, they only worked locally. If you wanted to run Get-Process and filter out the high memory processes on a remote server, you had to go to that server, logon, open PowerShell and run your command. Or figure out how to do it using Get-WMIObject.

Happily, these cmdlets in PowerShell 2.0 now sport a long needed -Computername parameter:

PS C:\> get-service -computername File01

You can now run the Get-Process command from your desktop, like this:

PS C:\> ps -ComputerName JDHIT01 | sort ws -desc | select -first 10

Handles NPM(K)   PM(K)   WS(K) VM(M) CPU(s)   Id ProcessName
------- ------   -----   ----- ----- ------   -- -----------
    388      9    4328  162140   181         472 services
   1172     44   22528   31876   125         936 svchost
    960     86   25580   30540    97         484 lsass
   5199    777   23300   22760    70        1352 dns
    522     48    9944   13996    95        1508 inetinfo
    612     65    9268   13216    64         424 winlogon
    303    331    8464   11532   102        1788 tcpsvcs
    351      8    7836   11464    83        2028 iexplore
    211      8    5340    8092    47        1172 spoolsv
    239     16    6156    7104    89        1716 wins

These parameters do NOT require that PowerShell 2.0 be installed on the remote machine. However you probably still will need it, as you'll run into some limitations. For example, the Stop-Service cmdlet does not have a -computername parameter, so you can't do this, for example:

PS C:\> gsv spooler -computername "jdhit01" | stop-service

Well, technically you can run this without error, as it will stop the spooler service on your machine. If you tried this, it will definitely fail:

PS C:\> gsv spooler -computername "jdhit01" | stop-service -computername "jdhit01"

The Stop-Service cmdlet simply doesn't support it.

The other limitation, before you get too excited, is that cmdlets like Get-Service and Get-Process, while now connecting to remote computers, can't use alternate credentials. The cmdlets will use the current credentials. If you need alternate credential support, you'll have to turn back to Get-WMIObject.

What I really want you to take away from this lesson is that you should re-read the help documentation for cmdlets in PowerShell 2.0 -- even those you have used in the past. You might be surprised by a new parameter or two.

About the Author

Jeffery Hicks is an IT veteran with over 25 years of experience, much of it spent as an IT infrastructure consultant specializing in Microsoft server technologies with an emphasis in automation and efficiency. He is a multi-year recipient of the Microsoft MVP Award in Windows PowerShell. He works today as an independent author, trainer and consultant. Jeff has written for numerous online sites and print publications, is a contributing editor at Petri.com, and a frequent speaker at technology conferences and user groups.

comments powered by Disqus
Most   Popular

Upcoming Training Events

0 AM
Live! 360 Orlando
November 17-22, 2024
TechMentor @ Microsoft HQ
August 11-15, 2025