I’m writing a PowerShell script to perform certain administrative functions in IIS 7.5.
import-module WebAdministration
In some cases I know the name of the web application I want to work with but not the web site it is under. Getting the application is easy:
$app = get-webapplication -name 'MyApp'
But I cannot figure out how to get the name of the web site given the app. It doesn’t seem to be a property off the webapplication object. Best I could come up with was trying to get it via test-path:
get-website | where {test-path "iis:\sites\$_.name\MyApp"}
For some reason that comes up empty. Any thoughts on how to go about this? Thanks in advance.
This is how you can get the site name:
Or even shorter: