Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Gathering IIS 6 website properties

Status
Not open for further replies.

hurtsmyhead

Technical User
Jun 3, 2010
8
Hi all,

I was put on an IIS migration project where we have to discover, then migrate the applications (websites) on several thousand Windows 2003/IIS 6.0 servers. I've been asked to put together a PowerShell script that would do the initial discovery, and I am definitely not a scripter of any sort. I found the below script on Technet, and by the description it seems to do a lot of what I need, plus some things I don't need...but it doesn't seem to work--it doesn't produce any output. I'm trying to learn PowerShell but I'm a complete newbie and I'm a long long way from having the ability to figure this out. I think the project will be over by the time I get this thing going.

I need the server name, the website name, and the app pool and asp.net version associated with that site. I need the output to provide one row of information per website, something like this if a server was hosting three websites:

server1 website1 DefaultAppPool 2.0.50727
server1 website2 AppPool2 1.1
server1 website3 AppPool3 2.0.50727

Can someone take a look at this script and at least tell me if you see any major issues with it, and maybe give me some tips?

Thanks


function get-iisProperties {
<#
.SYNOPSIS
Retrieves IIS properties for Virtual and Web Directories residing on a server.
.DESCRIPTION
Retrieves IIS properties for Virtual and Web Directories residing on a server.
.PARAMETER name
Name of the IIS server you wish to query.
.PARAMETER UseDefaultCredentials
Use the currently authenticated user's credentials
.NOTES
Name: Get-iisProperties
Author: Marc Carter
DateCreated: 18Mar2011
.EXAMPLE
Get-iisProperties -server "localhost"

Description
------------
Returns IIS properties for Virtual and Web Directories residing on a server.
#>
[cmdletbinding(
DefaultParameterSetName = 'server',
ConfirmImpact = 'low'
)]
Param(
[Parameter(
Mandatory = $True,
Position = 0,
ParameterSetName = '',
ValueFromPipeline = $True)]
[string][ValidatePattern(".{2,}")]$server
)
Begin{
$error.clear()
$server = $server.toUpper()
$array = @()
}

Process{
#define ManagementObjectSearcher, Path and Authentication
$objWMI = [WmiSearcher] "Select * From IIsWebServer"
$objWMI.Scope.Path = "\\$server\root\microsoftiisv2"
$objWMI.Scope.Options.Authentication = [System.Management.AuthenticationLevel]::packetPrivacy
$server

trap { 'An Error occured: {0}' -f $_.Exception.Message; break }

#Get System.Management.ManagementObjectCollection
$obj = $objWMI.Get()

#Iterate through each object
$obj | % {
$Identifier = $_.Name
[string]$adsiPath = "IIS://$server/"+$_.name
$iis = [adsi]$("IIS://$server/"+$_.name)
#Enum Child Items but only IIsWebVirtualDir & IIsWebDirectory
$iis.Psbase.Children | where { $_.SchemaClassName -eq "IIsWebVirtualDir" -or $_.SchemaClassName -eq "IIsWebDirectory" } | % {
$currentPath = $adsiPath+"/"+$_.Name
#Enum Subordinate Child Items
$_.Psbase.Children | where { $_.SchemaClassName -eq "IIsWebVirtualDir" } | Select Name, AppPoolId, SchemaClassName, Path | % {
$subIIS = [adsi]$("$currentPath/"+$_.name)
foreach($mapping in $subIIS.ScriptMaps){
if($mapping.StartsWith(".aspx")){ $NETversion = $mapping.substring(($mapping.toLower()).indexOf("framework\")+10,9) }
}
#Define System.Object | add member properties
$tmpObj = New-Object Object
$tmpObj | add-member -membertype noteproperty -name "Name" -value $_.Name
$tmpObj | add-member -membertype noteproperty -name "Identifier" -value $Identifier
$tmpObj | add-member -membertype noteproperty -name "ASP.NET" -value $NETversion
$tmpObj | add-member -membertype noteproperty -name "AppPoolId" -value $($_.AppPoolId)
$tmpObj | add-member -membertype noteproperty -name "SchemaClassName" -value $_.SchemaClassName
$tmpObj | add-member -membertype noteproperty -name "Path" -value $($_.Path)

#Populate Array with Object properties
$array += $tmpObj
}
}
}
}#End process
End{
#Display results
$array | ft -auto
}
}#End function


get-iisProperties -server localhost
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top