Skip to content

Instantly share code, notes, and snippets.

@nvnivs
Last active August 29, 2015 14:07
Show Gist options
  • Save nvnivs/1386ec085f71409d6ee0 to your computer and use it in GitHub Desktop.
Save nvnivs/1386ec085f71409d6ee0 to your computer and use it in GitHub Desktop.
Iterates through enabled IIS 6 websites and lists their bindings and A records. Useful in preparation to decommission Windows 2003 web servers. @PowerShell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://gist.githubusercontent.com/z0c/1386ec085f71409d6ee0/raw/'))"
<#
.Synopsis
Iterates through enabled IIS 6 websites and lists their bindings and A records.
Useful in preparation to decommission Windows 2003 web servers.
#>
$output = @()
$sites = Get-WmiObject -Class IIsWebServerSetting -Namespace "root\microsoftiisv2" -filter "ServerAutoStart=True"
foreach ($site in $sites) {
foreach ($binding in $site.ServerBindings) {
$obj = New-Object System.Object
$obj | Add-Member -type NoteProperty -name Name -Value $site.ServerComment
$obj | Add-Member -type NoteProperty -name Binding -Value $binding.Hostname
if ([string]::IsNullOrEmpty($binding.Hostname)) {
$obj | Add-Member -type NoteProperty -name Result -Value "Empty binding"
}
else {
try {
$ip = [System.Net.Dns]::GetHostEntry($binding.Hostname).AddressList[0].IPAddressToString
$obj | Add-Member -type NoteProperty -name Result -Value $ip
}
catch {
$obj | Add-Member -type NoteProperty -name Result -Value $_.Exception.Message
}
}
$output += $obj
}
}
$output | Sort-Object Result,Name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment