Network Computing is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.

Rolling Review: Windows 2008 Server PowerShell: Page 3 of 4

Before you take the CTP version of PowerShell 2.0 for a spin, you'll need to uninstall PowerShell 1.0--the hardest part of the upgrade--and install .Net 2.0 and WS Management 1.1. PowerShell 2.0 runs on x86 and x64 platforms of Windows XP-SP2, Windows Server 2003-SP2, Windows Vista, Windows Vista-SP1 Beta, and Windows Server 2008 RC0 and above. In addition to the new Remote administration capabilities, PowerShell 2.0 delivers a GUI-based shell environment that loosely resembles a simple developer's workspace. To use the GUI version of PowerShell 2.0, you'll need to install .Net 3.0.

While PowerShell is a terrific tool for remote administration, we wondered if we could solve other problems more quickly in the 2.0 version than in the GUI, or perform tasks more efficiently than with a resource kit utility. As we looked at the various bags of tricks that exist in cyberspace, it became clear that PowerShell's real value comes from being able to script and automate arduous, complicated tasks.

For example, we manage a large number of servers and wanted to see a consolidated list of stop errors, on demand and in a spreadsheet. With two lines of code, we were able to load a text file containing the host names of 25 servers in our lab environment, query each for a list of stop events generated in the system log in the past day, export the data to a spreadsheet, and automatically launch Excel to display the info. Pretty impressive for two lines of code. In another time-saving scenario, we were able to do a bulk import of 25 user accounts into Active Directory and easily populate those accounts with the appropriate user properties.

Finally, we found that PowerShell excels in file system administration. Say you're looking to clean up disk space--it's a snap to build a script that can search for files over 100 MB and export that data for easy viewing in Excel.

In the next edition of our Longhorn Rolling Review, we'll take an in-depth look at Server Core and reveal the advantages, and the gotchas, of this new installation option for Windows Server 2008.

10 Cool Things To Do With PowerShell

1. NUMBERS, PLEASE
Return only the serial number and version of the BIOS of your system, collected from the Win32_BIOS class
Get-WMIObject Win32_BIOS | Select-Object SerialNumber,Version

2. STATE OF THE UNION
List the services running on the PC; select and display service name and running state
Get-WMIObject Win32_Service | Select-Object Name,State

3. MAIL CALL

List services running on a remote system named "email"; select and display service name and running state
Get-WMIObject Win32_Service -computername email | Select-Object Name,State

4. RECENT HISTORY
Query and return the 100 most recent events in the system log for any events of type "Warning"
Get-eventlog -newest 100 -logname system | where-object {$_.entry Type -eq "Warning"}

5. KILL SWITCH
Kill the Excel process running on the local computer
Get-Process | Where { $_.Name -Eq "Excel" } | Kill

6. TESTING 1,2
Use WSMan to remotely execute the Get-Service Cmdlet on a host called "testPC"
Invoke-expression -command "Get-Service" -ComputerName testPC

7. ON THE RUN
Use WSMan to list all running processes on a remote host called "test PC"
invoke-expression -command "Get-Process" -ComputerName testPC

8. NINJA MAN

Use WSMan to remotely kill the Excel process on a host called "testPC"
invoke-expression -command "Stop-Process -processnameExcel" -ComputerName testP

9. STOP THE PRESSES
Remotely stop the print spooler service on a host called "testPC"
invoke-expression -command "Stop-Service -displayname 'Print Spooler'" -Computer-
Name testPC

10. AT YOUR SERVICE
One of our favorites, this two-line command exports a list of all
services to a csv file, and then launches Excel to display the data
Get-Service | Export-CSV c:\Processes.csv Invoke-Item c:\Processes.csv