Scan if a service exists and do accordingly

$temp = Get-Content C:\Users\……….\Desktop\<filename>.txt
foreach ($servername in $temp){
if( get-service -ComputerName $servername -name <servicename> -ErrorAction SilentlyContinue){
get-service -ComputerName $servername -name <Servicename> | select MachineName, DisplayName, Status
}
else {
$servername | out-file C:\Users\……..\Desktop\<filename>.txt -Append
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *