INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Gathering IIS 6 website properties

Gathering IIS 6 website properties

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close