Monthly Archive


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

Comments are closed.