The Need:
This week a guy at work asked me how he could query multiple servers for the status of some specific services.
The Script:
#Check-RemoteServices.ps1
#Grabs a list of servers
$Servers = (Get-Content C:\servers.txt)
#Pings each server in the list and if its up queries the services
$Servers | foreach {
$ping = gwmi win32_pingstatus -filter "address='$_'"
if($ping.statusCode -eq 0)
{
$srv = gwmi -query "select SystemName,Displayname,State,Startname,StartMode,Status from win32_service" -computer $_
$srv | Where {$_.Displayname -eq "DHCP Server"} | select SystemName,State,StartMode,DisplayName
$srv | Where {$_.Displayname -eq "DNS Server"} | select SystemName,State,StartMode,DisplayName
$srv | Where {$_.Displayname -eq "Windows Internet Name Service (WINS)"} | select SystemName,State,StartMode,DisplayName
$srv | Where {$_.Displayname -eq "SNMP Service"} | select SystemName,State,StartMode,DisplayName
$srv | Where {$_.Displayname -eq "Microsoft Exchange Information Store"} | select SystemName,State,StartMode,DisplayName
$srv | Where {$_.Displayname -eq "MSSQLServer"} | select SystemName,State,StartMode,DisplayName
}
#If the server does not respond a message is written the console
Else {write-host "$_ is not responding" -fore red}
}
Saturday, 9 May 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment