Search IIS Bindings

At my new job, I keep running into an issue where I am asked to make changes to a site and they only give me the URL binding. But in IIS the sites are listed by name and not URL. So if the names do not match then it becomes a pain in the butt to find what site is using the URL binding. Then I had to manually search IIS bindings until I found it.

I thought there had to be a faster way. So I started looking at what PowerShell could do with IIS and I came up with this script.

I am sure someone out there could make a better one but this is working very well for my needs.

IIS Binding search with PowerShell

IIS Bindings Search with Powershell

I run this script from the IIS server.

$search = Read-Host -Prompt 'Input search string '

$Websites = Get-Website

foreach ($Sites in $Websites)
{
    $Bindings = Get-WebBinding -Name $Sites.name | findstr /i $search

    if ($Bindings -ne $null)
    {
        Write-Output "---------------------"
        $sitename = "--- Site Name: " + $Sites.name + " ---"
        Write-Output $sitename

        $Bindings = Get-WebBinding -Name $Sites.name | findstr /i $search
        Write-Output $Bindings
    }
}

Line by line

First we get the search string.

$search = Read-Host -Prompt 'Input search string '

Next we pull all the website data into a variable we can work with.

$Websites = Get-Website

Then we start a for each loop to check all the sites one by one. For each site, we use findstr to see if anything in the bindings matches our search string. I use /i here so that it’s not a case sensitive match.

$Bindings = Get-WebBinding -Name $Sites.name | findstr /i $search

If that does not return null, meaning that it found something, then we go into this if statement and print the site name and binding info.

if ($Bindings -ne $null)
    {
        Write-Output "---------------------"
        $sitename = "--- Site Name: " + $Sites.name + " ---"
        Write-Output $sitename

        $Bindings = Get-WebBinding -Name $Sites.name | findstr /i $search
        Write-Output $Bindings
    }

Good Luck

I hope this helps you save some time tracking down IIS bindings. I know I looked for 30mins or so trying to find a script like this and failed. So hopefully this will help someone else.

And if you know of a better way to do this then leave a comment below. I’d love to learn about it.


Join The Community

I hope you enjoyed this article! I'm always trying to post new and helpful things! If you like what you see then I'd love to be able to send you more! Please subscribe to my newsletter so that I can send you updates.

Leave a Reply

Your email address will not be published. Required fields are marked *