Knight Talks Tech

Checking services with Powershell

I use this script to check the Oracle services on the list of servers contained in servers.txt. The results are output to ServiceResults.html file.
Listing for checkServices.ps1

process{
$servername = $_
$serviceArray = Get-WmiObject -class Win32_Service -computerName $servername
$temp = @()
$serviceArray foreach {
$serviceinfo = “” select servername, name, startmode, state, status
if (($_.name -like “*Oracle*”)) {
$serviceinfo.servername = $servername
$serviceinfo.name = $_.name
$serviceinfo.startmode = $_.startmode
$serviceinfo.state = $_.state
$serviceinfo.status = $_.status
$temp +=$serviceinfo
}
}
$temp
}

I call this script file by the following:
Get-Content C:\PowershellScripts\servers.txt C:\PowershellScripts\checkServices.ps1 convertTo-Html out-file C:\PowershellScripts\ServiceResults.html

Exit mobile version