title: PowerShell + WebAdministration - How to get website from webapplication?
body: <p>I'm writing a PowerShell script to perform certain administrative functions in IIS 7.5.</p>
  
  <pre><code>import-module WebAdministration
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>$app = get-webapplication -name 'MyApp'
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>get-website | where {test-path "iis:\sites\$_.name\MyApp"}
  </code></pre>
  
  <p>For some reason that comes up empty. Any thoughts on how to go about this? Thanks in advance.</p>