我已经能够从远程服务器获取网站名称,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
}
答案 0 :(得分:0)
你可以从这开始:
$lf = @{n='LogFile';e={Join-Path ($_.LogFile.Directory -replace '^%SystemDrive%','C:') "W3SVC$($_.Id)"}}
$pp = @{n='PhysicalPath';e={$_.Applications['/'].VirtualDirectories['/'].PhysicalPath}}
$server.Sites | Select Id,Name,$lf,$pp
答案 1 :(得分:0)
将制表符分隔列表另存为文本文件:
New-Item c:\sites.txt -type file -force
[Void][Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration")
$sm = New-Object Microsoft.Web.Administration.ServerManager
foreach($site in $sm.Sites)
{
$root = $site.Applications | where { $_.Path -eq "/" }
$rootVdir = $root.VirtualDirectories | where { $_.Path -eq "/" }
Write-Output ($site.Name + "`t" + $site.State + "`t" + $rootVdir.PhysicalPath + "`t" + $site.Id + "`t" + $site.Bindings + "`t" + $root.ApplicationPoolName) >> c:\sites.txt
}