Monthly Archive


PowerShell and IIS

IIS information

In my recent post about getting server information from a IIS web server I said I post about getting similar information from later machines.


You still have the root\MirosoftIISv2 namespace available if you install the IIS 6.0 tools but one question to keep in mind – how long will they continue to be available?


Your alternative is the root\webadministration names space. You can use the Site class to get the relevant information


$serverdata = @()
Get-CimInstance -Namespace root\webadministration -ClassName Site -ComputerName $env:COMPUTERNAME |
foreach {

$serverdata += New-Object -TypeName PSObject -Property @{
Port = [string]::Join(',', ($_.Bindings | select -ExpandProperty BindingInformation))
SiteName = $_.Name
SiteId = $
PSComputerName = $_.PSComputerName
Status = Invoke-CimMethod -InputObject $_ -MethodName GetState | select -ExpandProperty ReturnValue



Remember that COM objects are inert so you can’t call the method directly on the object. otherwise the info is about the same

IIS 6.0 server information

A question of the forum asked about getting data from IIS 6.0 servers


One of the ways to access this data is to use CIM (WMI). IIS 6.0 has the root\MicrosoftIIsV2  namespace. Later versions of Windows server also have a root\webadministration namespace which is preferred.


The original question asked about IIS 6.0 – I’ll show the same functionality using the later namespace in the next post


This based on the original code in the question and isn’t necessarily how I would do it from scratch

$file = Get-Content "C:\Temp\PowerShellScripts\IISQuery\servers.txt"
$OutputDir = "C:\Temp\PowerShellScripts\IISQuery\Output"
$OutputFile = Join-Path $OutputDir "IIStest.csv"
$serverdata = @()

foreach ($computername in $file)
$IISWebServer = Get-WmiObject -Namespace root\MicrosoftIIsV2 -Class IISWEbServer -ComputerName $computername -Authentication 6
foreach ($webserver in $IISWebServer) {

$IISWebServerSet = Get-WmiObject -Namespace root\MicrosoftIISv2 -Class IISWebServerSetting -ComputerName $computername -Filter "Name='$($webserver.Name)'"  -Authentication 6

$serverdata += New-Object -TypeName PSObject -Property @{
PScomputername = $IISWebServerSet.PScomputername
ServerComment = $IISWebServerSet.ServerComment
SiteStatus = $webserver.ServerState
Bindings = [string]::join(';',($IISWebServerSet.ServerBindings | select -expand hostname))
Port = [string]::join(';',($IISWebServerSet.ServerBindings | select -expand Port))
SiteName = $IISWebServerSet.Name

} ## end of foreach ($webserver in $IISWebServer)

}  ## end of foreach ($computername in $file)
$serverdata | Export-Csv -Path $OutputFile –NoTypeInformation


Start by defining input and output files and an empty array


Loop through the servers and get the IISWebserver class instance. You’ll get one object per web site. Loop through the sites and get the IISWebServerSetting class for that site (using –Filter).


Create and output object and add to the array

Export the array to a csv file


There are a few improvements that could be made to this to make it more efficient that I’ll cover in a later post

Learn Windows IIS in a Month of Lunches

Jason Helmick’s book in the Month of Lunches series is now available -

I really can’t recommend this book enough – if you’re new to IIS or want to learn how to administer IIS with PowerShell – this is the book for you.

Buy it – you won’t be disappointed.

PowerShell in Practice offer today only

Manning have PowerShell in Practice on a half price offer today. Go to and use code dotd0330cc when ordering

PowerShell IIS snapin

The PowerShell IIS snapin has been officially released.  Download it from

Technorati Tags: PowerShell,IIS