2016-09-29 1 views
0

서버 목록 (server.txt)이 있는데 모든 서버의 "Nimsoft Robot Watcher"서비스 상태를 가져 오려고합니다. 첫 번째 서버가 표시됩니다에 대한Get-Content에서 Get-Content 사용

$text1 = Get-Content server.txt 
foreach ($text1 in Get-Content server.txt) 
{ 
    $text=$text1 
} 
Get-Service -ComputerName $text -DisplayName "Nimsoft Robot Watcher" 

만 상태 :

나는 코드를 시도했다.

답변

0

현재 가지고있는 코드는 각 반복마다 $text 값을 바꿀 것이며 루프가 완료된 후에 성을 남겨 둡니다.

어느 배열에서 호스트를 수집하고 @Asgar 작정 Get-Service

$text = Get-Content server.txt 
Get-Service -ComputerName $text -DisplayName "Nimsoft Robot Watcher" 
+0

감사 되었 루프

foreach ($text in Get-Content server.txt) { Get-Service -ComputerName $text -DisplayName "Nimsoft Robot Watcher" } 

또는 내부 Get-Service을 넣어, 그 작동합니다.! :) –

+0

서비스를 받기 전에 서버 이름을 추가해야합니다. –

+0

'Get-Service'에 의해 반환 된 객체는 'MachineName' 속성을 갖습니다. –

관련 문제