我已经能够从远程服务器获取网站名称、ID 和日志文件位置。查找每个站点根目录的物理路径不太直观,并且在此消息末尾的循环中。这是访问每个站点物理路径的正确方法吗?我需要这个来测量每个站点的磁盘使用情况。
[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
}