【问题标题】:Is this a correct way use powershell to get physical path of each site on a remote IIS server?这是使用 powershell 获取远程 IIS 服务器上每个站点的物理路径的正确方法吗?
【发布时间】:2015-12-11 00:16:55
【问题描述】:

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

【问题讨论】:

    标签: iis powershell


    【解决方案1】:

    你可以从这个开始:

    $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
    

    【讨论】:

      【解决方案2】:

      将制表符分隔的列表保存为文本文件:

      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
      }
      

      【讨论】:

        猜你喜欢
        • 2011-04-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-09-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多