<< A B C D E F G H I J K L M N O P Q R S T U V W X Y Z



bindings, find all IPs for a server and sort by IP address

This works OK if you happen to already be on the web server in question

Import-Module WebAdministration
$sites = Get-ChildItem IIS:\sites
$bindings = $sites | foreach-object {$_.Bindings} | foreach-object {$_.Collection} | foreach-object {$_.BindingInformation}
$bindings | Sort-Object

But if you're not already on the web server in question, starting a remote session can speed things up. I also like to split out the various parts of the returned object into separate columns.

$serverName = "someWebServer"
$Session = New-PSSession -ComputerName $serverName
$block = {Import-Module WebAdministration
    $sites = Get-ChildItem -path IIS:\Sites
    $bindings = $sites | foreach-object {$_.Bindings} | foreach-object {$_.Collection} | foreach-object {$_.BindingInformation}
    $bindings | Select @{name="IP"; expression={$_.Split(":")[0]}}, @{name="port"; expression={$_.Split(":")[1]}}, @{name="domain" ; expression={$_.Split(":")[2]}} | sort domain | ft
Invoke-Command -Session $Session -ScriptBlock $block

In this case, I was most interested in sorting by domain. But Often I want to know if an IP address is being used, so I'll sort by that instead. Unfortunately, you can't pipe to an Out-GridView in a remote session and I haven't figured out yet how to return a variable's result to the local session so I can pipe that to an Out-GridView. So, I content myself with Format-Table.








IP addresses, list - see bindings, find all IPs for a server and sort by IP address





memory leak, monitor progress for

One of your site's app pools might have to be restarted periodically because it runs out of memory due to a memory leak. If you want more time-based granular detail, schedule this code to run periodically in the task scheduler.

$memorySCC = Get-Process -includeUserName | ? {$_.UserName -eq "IIS APPPOOL\yourDomain.com"} | Select-Object -property workingSet64
$time = Get-Date -Format g
$obj = New-Object psObject
$obj | Add-Member -MemberType noteProperty -Name time -Value $time
$obj | Add-Member -MemberType noteProperty -Name memory -Value $memorySCC.workingSet64
$obj | Export-Csv c:\scripts\output.csv -noType -Append