简体   繁体   English

这是使用Powershell获取远程IIS服务器上每个站点的物理路径的正确方法吗?

[英]Is this a correct way use powershell to get physical path of each site on a remote IIS server?

I've been able to get the website names, ids and logfile locations from the remote server. 我已经能够从远程服务器获取网站名称,ID和日志文件的位置。 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. 我需要它来衡量每个站点的磁盘使用情况。

[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
}

You can start with this: 您可以从以下内容开始:

$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

To save a tab separated list as a text file: 要将制表符分隔的列表另存为文本文件,请执行以下操作:

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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM