I'm running this code below as a function to iterate through a list of servers to check if services are running. This works when run manually. When run from a scheduled task the code $arrService.Status
translates to the service name. I even tried something like Get-Service -Computer $Server -display $ServiceName | Select -expandproperty Status
but that returns empty string or no value.
Any idea why the status property would not work when run from a scheduled task?
function CheckService{
param($Server, $ServiceName)
$arrService = Get-Service -Computer $Server -display $ServiceName
if ($arrService.Status -ne "Running"){
Start-Service -InputObject $ServerService
}
}