title: Is this a correct way use powershell to get physical path of each site on a remote IIS server?
body: <p>I've been able to get the website names, ids and logfile locations from the remote server.  Finding the physical path of each sites root was less intuitive and is in the loop at the end of this message.  Is that the right way to access each sites physical path?  I'll need this to measure each sites disk usage.</p>
  
  <pre><code>[Void][Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration")
  $server = [Microsoft.Web.Administration.ServerManager]::OpenRemote($machine)
  $sites = $server.Sites #| Select Id, Name, LogFile
  
  IF ( $sites.count -ne 0 ) 
  {
      $logRootDir =$sites[0].LogFile.Directory
      write-host "log root dir = $logRootDir" 
  }
  ELSE 
  {
      write-host "there are no IIS websites on this machine"
      Exit
  }
  
  foreach ($site in $sites) 
  {
      write-host $site.Id $site.Name
      $rootApp = $site.Applications | where { $_.Path -eq "/" }
      $rootVdir = $rootApp.VirtualDirectories | where { $_.Path -eq "/" }
      write-host "root dir = " $rootVdir.PhysicalPath
  }
  </code></pre>