【问题标题】:How to export all the IIS site and App-pool details to Excel sheet如何将所有 IIS 站点和应用程序池详细信息导出到 Excel 表
【发布时间】:2020-01-28 07:36:51
【问题描述】:

我编写了一个 PS 脚本,其中会将所有 IIS 站点详细信息导出到 Excel 工作表,但是当我尝试使用 IIS 应用程序池时,它没有给出应用程序池的所有参数和数据的输出显示在站点详细信息之后,但我需要与同一行中的站点数据并行的应用程序池数据,请帮助我解决此问题。

代码

Clear-Host
$computers = Get-Content "C:\TEMP\servers.txt" 


    Invoke-Command -ComputerName $computers -ScriptBlock {
    & {
    Get-Website | Select-Object Name,Id,State,PhysicalPath,
@{n="Bindings"; e= { ($_.bindings | select -expa collection) -join ‘;’ }} ,
@{n="attributes"; e={($_.attributes | % { $_.name + "=" + $_.value }) -join ‘;’ }}
Get-IISAppPool | Select-Object Name,Status,CLRVer,PipeLOneMode,StartMode
}
} | Export-Excel -Path C:\users\$env:username\documents\IIS_sites.xlsx```


**Output**
*name           :Test
id             : 2
state          : Started
physicalPath   : C:\Chadrakanth
Bindings       : http 123.com
attributes     : name=2696Test;id=2;serverAutoStart=False;state=1
PSComputerName : AAA
RunspaceId     : 8ec7998e-03e0-47c7-b96a-ffae96260922

Name           : DefaultAppPool
Status         : 
CLRVer         : 
PipeLOneMode   : 
StartMode      : OnDemand
PSComputerName : AAA
RunspaceId     : 8ec7998e-03e0-47c7-b96a-ffae96260922*

【问题讨论】:

  • Get-IISAppPool cmdlet 的文档说输出的类型为 ApplicationPool,它似乎没有 StatusCLRVerPipeLOneMode。您是否在寻找 StateManagedRuntimeVersionManagedPipelineMode 属性?
  • 感谢您的回复,我还有一个疑问,当我将 IIS 站点和应用程序池详细信息导出到 Excel 时,如何在同一行中获取它,截至目前,应用程序池详细信息在 IIS 站点详细信息之后导出
  • 您可以将Get-WebsiteGet-IISAppPool 保存到变量中,然后使用[pscustomobject]New-Object 构建您想要的对象。例如$Website = Get-Website; [pscustomobject]@{id = $Website.id}
  • 如果可能的话,请您帮我编写脚本

标签: powershell


【解决方案1】:

如 cmets 中所述,StatusCLRVerPipeLOneMode 不是可用属性,已分别替换为 StateManagedRuntimeVersionManagedPipelineMode

此外,由于每个网站都是 AppPool 的成员,因此需要遍历网站并为每个网站找到适当的 AppPool。然后可以使用[PSCustomObject] 类型加速器将属性组合成一个对象。

$Computers = Get-Content "C:\TEMP\servers.txt" 

Invoke-Command -ComputerName $Computers -ScriptBlock {
    # Changed to newer IISAdministration Module to match Get-IISAppPool
    $Websites = Get-IISSite

    foreach ($Website in $Websites) {

        $AppPool = Get-IISAppPool -Name $Website.Applications[0].ApplicationPoolName

        [PSCustomObject]@{
            WebsiteName                  = $Website.Name
            WebsiteId                    = $Website.Id
            WebsiteState                 = $Website.State
            WebsitePhysicalPath          = $Website.PhysicalPath
            WebsiteBindings              = $Website.Bindings.Collection -join ';'
            WebsiteAttributes            = ($Website.Attributes | ForEach-Object { $_.name + "=" + $_.value }) -join ';'
            AppPoolName                  = $AppPool.Name
            AppPoolState                 = $AppPool.State
            AppPoolManagedRuntimeVersion = $AppPool.ManagedRuntimeVersion
            AppPoolManagedPipelineMode   = $AppPool.ManagedPipelineMode
            AppPoolStartMode             = $AppPool.StartMode
        }
    }
} | Export-Excel -Path C:\users\$env:username\documents\IIS_sites.xlsx

【讨论】:

  • 使用相同的脚本我无法获取物理路径和绑定集合详细信息,请您帮我解决这个问题
  • 当我将命令从 Get-IISSite 更改为 Get-Website 时,我能够获取物理路径和绑定详细信息,但 APP 池部分不起作用。如果我保持相同的 Get-IISSIte,我无法获取物理路径和绑定详细信息,请帮助我解决此问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-17
相关资源
最近更新 更多