Pages

Saturday, 3 November 2018

Bulk check for a Service

The following PowerShell code was developed to get the status of a specific Service on a list of PCs. It was used to diagnose how many PCs with a piece of licensing software had become inactive - a task requiring bulk automation.

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
#The script requires a text file containing the names of the PCs to query. It will work through each one in turn
ForEach ($Computer in Get-Content 'Computers.txt') {

    #A list of Services for the PC are acquired, then piped through to specifically find the one that equals the value 'ServiceName'
    If (Get-Service -ComputerName $Computer | Where-Object {$_.Name -eq 'ServiceName'}) {

        #Output the results to the PowerShell console (with a ForegroundColor to help. Also displays the name of the current PC from the input text file
        Write-Host "$Computer service found" -ForegroundColor Green
    }
    Else {
        Write-Host "$Computer service not found" -ForegroundColor Yellow
    }
}
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

Bulk check for a Service.ps1

No comments:

Post a comment