【发布时间】:2018-12-12 20:51:11
【问题描述】:
我想在所有远程服务器(大约 100 台服务器)上远程运行一个命令。这个命令收集所有 iis 并保存在一个 txt 文件中。
(C:\Windows\System32\inetsrv\appcmd.exe list app >C:\Temp\list.txt)
当然,我的问题是如何在我的本地机器中获取所有远程的列表。我不想收集远程服务器上的每个列表。
$Servers = @("remotemachine1", "remotemachine2", "remotemachine3" )
foreach ($server in $Servers) {
$PSSession=New-PsSession -ComputerName $server
Invoke-command -Session $PSSession -ScriptBlock {
Write-Verbose -Message "Server: $env:ComputerName" -Verbose
C:\Windows\System32\inetsrv\appcmd.exe list app >C:\Temp\list.txt
}
}
Get-PSSession | Remove-PSSession
【问题讨论】:
标签: powershell iis powershell-4.0 powershell-remoting