scripting - Powershell Script - Services Running eq OK or list Services Not Running -


i have script checks multiple servers particular services running.

i need assistance or pointers on how not pull running / not running response. need "if queried services running = ok, if not list service not running"

is doable?

script:

$check1 = get-service -computername server1 -name *service1* | convertto-html name,status -fragment $check2 = get-service  -computername server2 -name *service2* | convertto-html name,status   $check3 = get-service  -computername server3 -name *service3* | convertto-html name,status $check4 = get-service -computername ukvault01 -name *service4* | convertto-html name,status convertto-html -body "<b>check1</b> $check1 <br> <b>check2</b> $check2 <br> <b>check3</b> $check3<br> <b>check4</b> $check4" -title "service checks" | out-file c:\statusreport.html 

encapsulate checks in function this:

function check-service{$server, $name) {   $check = get-service $server -name $name | ? { $_.status -ne "running" }   if ( $check -eq $null ) { $check = "ok" }   $check | convertto-html -fragment }  $check1 = check-service server1 *service1* $check2 = check-service server2 *service2* ... 

Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -