Skip to content

Instantly share code, notes, and snippets.

@davidroberts63
Created November 29, 2016 21:56
Show Gist options
  • Save davidroberts63/a82f1d46f623c7627112e5a86a96831e to your computer and use it in GitHub Desktop.
Save davidroberts63/a82f1d46f623c7627112e5a86a96831e to your computer and use it in GitHub Desktop.
Get site bindings for all apppools
import-module webadministration
$ErrorActionPreference = "SilentlyContinue"
$bindings = Get-WebBinding
$bindings | Select -First 1 *
function GetAppPoolApps($appPool)
{
if($appPool -like "#{*") { return }
$apps = Get-WebConfigurationProperty "/system.applicationHost/sites/site/application[@applicationPool='$appPool']" "machine/webroot/apphost" -name path -ErrorAction SilentlyContinue
if(!$apps) { return }
$apps = $apps.ItemXPath
foreach ($s in $apps) {
$binding = $bindings | Where { $s.Contains($_.ItemXPath) } | Select -First 1 -ExpandProperty bindingInformation
$name = $s -replace "\/system.applicationHost\/sites\/site\[\@name='", ""
$name = $name -replace "[\w-]+' and \@id='\d{1,10}'\]\/application\[\@path='", ""
$name = $name -replace "'\]",""
$out += $binding + $name + "`n"
}
return $out
}
dir iis:\apppools | Where { $_.State -eq "Started" } | %{ GetAppPoolApps($_.Name) } | Out-File "temp-bindings.txt"
New-OctopusArtifact "temp-bindings.txt" "$(hostname).txt"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment