2017-02-17 1 views
0

I가 내가 여러 서버 현재이 출력 그것에서 실행되는 서버에 저장되어 PowerShell 명령

Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | 
    Select-Object DisplayName, DisplayVersion, Publisher | #InstallDate 
    Format-Table –AutoSize | 
    Out-File C:\Temp\InventoryTestScripts.txt 

에 대해 실행하려면 다음 스크립트. 30 개의 다른 서버에 대해이 명령을 실행하고 각 서버의 출력을 하나의 파일에 저장하고 싶습니다. 또한 어떤 결과 집합이 파일의 어떤 서버에서 왔는지 나타내는 방법이 필요합니다.

+0

'Invoke-Command'를보세요. 곧 전체 답변을 드리겠습니다. – JohnLBevan

+2

SO에서 제목을 검색하면 다음과 같이 표시됩니다. http://stackoverflow.com/questions/24009970/how-to-run-a-command-against-multiple-servers-simultaneously-in-powershell. 속임수 여야합니다. 다른 사람들도있을 것입니다. – Matt

답변

0
[string[]]$servers = 'server1,server2,server3' -split ',' #put a list of servers into an array; you can get these however (typically read from a file; in this case splittling a comma separated string) 
$credential = Get-Credential #this will prompt you to enter your account credentials 
Invoke-Command -ComputerName $servers -Credential $credential -ScriptBlock { 
    Get-ItemProperty 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate 
} | Format-Table PSComputerName, DisplayName, DisplayVersion, Publisher, InstallDate 
+1

정말 고마워요! – Amicheals