November 2010 (1)
August 2010 (1)
July 2010 (1)
June 2010 (3)
July 2009 (3)
June 2009 (1)
May 2009 (1)
February 2009 (1)
January 2009 (1)
November 2008 (3)
October 2008 (4)
September 2008 (9)
August 2008 (6)
July 2008 (3)
June 2008 (3)
January 2008 (1)
November 2007 (2)
October 2007 (6)
September 2007 (5)
August 2007 (22)
July 2007 (6)
June 2007 (1)
May 2007 (3)
April 2007 (27)
March 2007 (8)
February 2007 (6)
September 2006 (2)
August 2006 (4)
July 2006 (9)
June 2006 (17)
May 2006 (20)
April 2006 (12)
March 2006 (9)
February 2006 (4)
January 2006 (3)
December 2005 (2)
November 2005 (4)
October 2005 (5)
September 2005 (37)
August 2005 (83)
July 2005 (6)

Active Directory / LDAP (0)
ASP.Net (19)
Blackberry Development (4)
c# (34)
c++ (3)
Code Camp (1)
Excel (1)
Exchange (3)
Front Page 2003 (6)
FTP User Editor (4)
HTML / CSS / DHTML (8)
IIS (146)
IIS - Log Parser (7)
IIS / FTP (12)
IIS / Tools / Administration (42)
IIS / Tools / Authentication (6)
IIS / Tools / Compression (8)
IIS / Tools / Crash & Hang (12)
IIS / Tools / ISAPI Filters (17)
IIS / Tools / Log Files (17)
IIS / Tools / Scripts (28)
IIS / Tools / Security (9)
IIS / Tools / SSL (6)
IIS 7 (3)
Internet Information Server (1)
Me (Chris Crowe) (6)
MIME Types (1)
Misc (72)
Oulook Express (2)
Silverlight (1)
SQL Server (27)
SQL Server CTE (1)
Vista (15)
Vista Gadgets (8)
Visual Studio (11)
Voice over BroadBand (1)
Windows (33)
Windows Powershell (3)
Windows Sharepoint Services (0)
Windows Sharepoint Services (15)
Windows Vista (14)
Wine Cellar (1)
WMI (8)
Windows Powershell (3) blog.crowe.co.nz.Models.Category

Windows Powershell

Free Windows PowerShell course book available for download

The book gives you a short introduction with many exercises about the interactive part of Windows PowerShell as well as some hints how to use other objects like WMI, .NET or COM objects like Excel or Internet Explorer.

The book is available for free and you can share it with all your colleagues or friends if you leave it as it is. The books can be used with or without the demo files available.


Windows PowerShell - WMI and IIS

A simple example to return all the fields in the IISWebService object on an IIS 6 computer using Windows PowerShell and the get-wmiobject cmdlet.

A simple example to return just the name fields from the IISWebServer object on an IIS 6 computer.

 


Windows PowerShell

Windows PowerShell is a new command-line shell and task-based scripting technology that provides comprehensive control and automation of system administration tasks.

Windows PowerShell allows Windows administrators to be more productive by providing numerous system administration utilities, consistent syntax, and improved navigation of common management data such as the registry or Windows Management Instrumentation (WMI).

Windows PowerShell also includes a scripting language which enables comprehensive automation of Windows system administration tasks. The Windows PowerShell language is intuitive and supports existing scripting investments. Exchange Server 2007 and System Center Operations Manager 2007 will be built on Windows PowerShell.

Windows Powershell has also been known under the code name Monad and is currently in Release Candiate.

Mondad is built on top of the .NET Framework version 2 and basically allows you to create scripts called cmdlets that you register with the system and then can reuse at any time.

A cmdlet is referred to by a verb and noun pair, separated by a "-":

get-process

These cmdlets can be piped together using the pipe character (same as the old DOS pipe command) |   But unlike the simple DOS pipe command you can concatinate any monad cmdlets to product interesting and very powerful results.

For the download url go to http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx

The download is 2.2 MB for RC1 and requires that you register prior to downloading.

side note: I had problems with the Microsoft Passport logging into this site so I logged into another Microsoft Passport site and then went back to the Powershell registration url and it worked fine.

An example to find all services that are stopped on your machine

  • get-service | where-object {$_.status -eq "stopped"}

To find all services where their name contains the name “SQL“

  • get-service | where-object {$_.status -like "*SQL*"}

Now this may be very nice but how about something complex such as doing a DIR on the registry from within your script?

What about using IPConfig.exe a standard console application to display an IP Address?

Typing IPCONFIG into the Powershell returns the standard data you woud expect (something like this)

Windows IP Configuration

Ethernet adapter Wireless Network Connection:

        Connection-specific DNS Suffix  . :
        IP Address. . . . . . . . . . . . : 192.168.2.3
        Subnet Mask . . . . . . . . . . . : 255.255.255.0
        Default Gateway . . . . . . . . . : 192.168.2.1
 

Using a Powershell filter you can get the IP Address very simply by itself without the other details.

This is just touching the surface of this powerful tool. You can create functions with looping, variables, regular expressions and so much more..

A good site that has quite a few scripts is at http://www.reskit.net/monad/samplescripts.htm and also the Microsoft Script Center web site has a category for Powershell Scripts at http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx

Remember to download go to http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx