Powershell: Get-service check running or not running -
Powershell: Get-service check running or not running -
i have next problem:
when use:
get-service -name ccmexec -erroraction silentlycontinue i follow list:
status name displayname ------ ---- ----------- running ccmexec sms agent host or
status name displayname ------ ---- ----------- stopped ccmexec sms agent host when use
$service = get-service -name ccmexec -erroraction silentlycontinue -computername $computername write-host "$service" i see ccmexec not "running' or stoppend".
if want see write-host status utilize this:
write-host $service.status or this:
write-host "$($service.name) $($service.status)" there couple of problems code presented in comment. first, you're using multiple if statements, rather if, elseif, and/or else. (you aslso utilize switch statement.) second, it's matching both running , $null because you're using -match instead of eq. seek instead:
if ($ccmservice.status -eq "running") { $excelcell.cells.item($excelrow, 11) = "running" } elseif ($ccmservice.status -eq "stopped") { $excelcell.cells.item($excelrow, 11) = "not running" } elseif ($ccmservice.status -eq $null) { $excelcell.cells.item($excelrow, 11) = "not installed" } you can more details on powershell's comparing operators here.
powershell service sccm
Comments
Post a Comment