1

我已经能够从远程服务器获取网站名称、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
}
4

2 回答 2

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
于 2013-03-20T14:50:42.723 回答
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
}
于 2015-12-10T15:57:40.723 回答