2016-07-09 3 views
0

원격 컴퓨터에서 서비스 목록을 모니터링하고 싶습니다. 이러한 서비스는 모든 원격 시스템에서 동일하지 않습니다.원격 컴퓨터의 서비스 목록을 모니터링하는 방법은 무엇입니까?

내가 가진 가장 가까운 것은 원격 컴퓨터에서 중지되는 모든 서비스를 모니터링하는 것이지만 서비스 목록을 모니터하는 방법을 스크립트하는 방법을 찾는 것 같습니다.

$Date = Get-Date -Format dd-MMM-yyyy 
$Time = Get-Date -Format "hh:mm:ss tt" 
$Style = @" 
<!DOCTYPE html> 
<html> 
... 
"@ 

$ServerList = Get-Content -Path C:\temp\computers1.txt 
$body = $ServerList | 
     Foreach-Object { 
      Get-Service -ComputerName $_ | Where-Object { 
      $_.Status -ne "Running" -and 
      $_.StartType -like "Automatic" 
      } 
     } | 
     Select-Object MachineName, Status, DisplayName, StartType | 
     Sort-Object -Property MachineNAme -Descending | 
     ConvertTo-Html 

$colorTagTable = @{ 
    Stopped = ' bgcolor="#ff0000">Stopped<'; 
    Running = ' bgcolor="#00ff00">Running<' 
} 

# get possible values look them in text sorrounded by > < and replace 
# them with style (pun intended). 
$colorTagTable.Keys | foreach { 
    $body = $body -replace ">$_<", ($colorTagTable.$_) 
} 

ConvertTo-Html -Head $Style -Body $body | Out-File "C:\temp\srv.htm"  

답변

1

의문이 documentation을 읽어

이 내가 일하고 스크립트입니다.

-ComputerName < 문자열 [] >
은 지정된 컴퓨터에서 실행중인 서비스를 가져옵니다. 기본값은 로컬 컴퓨터입니다.
원격 컴퓨터의 NetBIOS 이름, IP 주소 또는 FQDN (정규화 된 도메인 이름)을 입력하십시오. 로컬 컴퓨터를 지정하려면 컴퓨터 이름, 점 (.) 또는 로컬 호스트를 입력합니다.
[...] 문자열 [] >
검색 할 수있는 서비스의 서비스 이름을 지정
- 이름 <. 와일드 카드는 허용됩니다. 기본적으로이 cmdlet은 컴퓨터의 모든 서비스를 가져옵니다. 서비스 중 어느 것도 당신이 오류가 발생합니다이 경우 해당 컴퓨터에서 실행되지 않는 특정 컴퓨터에 존재하지 않는

$Style = @" 
<style> 
... 
</style> 
"@ 

$ServiceList = 'NetLogon', 'Spooler', 'W32Time' 
$ServerList = Get-Content -Path C:\temp\computers1.txt 

Get-Service -ComputerName $ServerList -Name $ServiceList | 
    Select-Object MachineName, Status, DisplayName, StartType | 
    Sort-Object -Property MachineNAme -Descending | 
    ConvertTo-Html -Head $Style | 
    Out-File 'C:\temp\srv.htm' 

서비스는 무시됩니다. 매개 변수를 무시하려면 Get-Service을 매개 변수 -ErrorAction SilentlyContinue과 함께 실행하십시오.

0

서비스 목록을 실제로 실행해야 서비스를받을 대신 로그의 이메일 보고서 및 확인 HTML 페이지

$servicelist=Get-WmiObject -Class Win32_Service -Filter "state = 'stopped' and startmode = 'auto'" | select Name 


$From = "[email protected]" 
$To = "[email protected]" 
$Subject = "Daily Service Report From " 
$Body = "get-content C:\temp\srv.htm " 
$SMTPServer = "smtp.email.com" 
#$SMTPPort = "587" 
Send-MailMessage -From $From -to $To -Subject $Subject ` 
-Body $Body -SmtpServer $SMTPServer #-port $SMTPPort 
을 가지고 이런 식으로 뭔가를해야합니다
관련 문제