繁体   English   中英

如何使用 Poweshell 脚本将 IIS 站点详细信息从多个服务器导出到 Excel 表

[英]How to export the IIS site deatils to excel sheet from multiple servers using Poweshell script

我编写了一个脚本,其中该脚本仅提供一台服务器的 IIS 详细信息,但我需要使用同一脚本的多台服务器的 IIS 站点详细信息。

Import-Module WebAdministration


    get-website | select Name,Id,State,physicalpath,
    @{n="Bindings"; e= { ($_.bindings | select -expa collection) -join ‘;’ }} ,
    @{n="LogFile";e={ $_.logfile | select -expa directory}},
    @{n="attributes"; e={($_.attributes | % { $_.name + "=" + $_.value }) -join ‘;’ }}| 
    Export-Csv -NoTypeInformation -Path C:\Temp\IIS_sites.csv

试试这个:请注意,如果远程机器上的 winRM 关闭,这将不起作用

$Machines = @('machine1','machine2') # list of your machines
foreach($M in $Machines)
{
    Invoke-Command -ComputerName $M -ScriptBlock {
    & { 
        # your script here
    }
}

} 

此外,如果您希望从命令中获得输出,并希望将它们保存在不同的变量中,请使用以下命令:

$Responses = Invoke-Command -ComputerName somecomp -ScriptBlock { (Get-Website), (Get-Process) }

#IIS Sites:
$Responses[0]

#Processes
$Responses[1]

暂无
暂无

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

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