$ Service_error = ""
$ I = $ J = 0
$ Filebase = Get-content D: \ PS \ servicebase.txt
$ Service_curr = Get-wmiobject-class win32_service-computer localhost
For ($ I = 0; $ I-lt $ service_curr.length; $ I ++)
{
$ Pattern_name = "^ \ W {7} \ s \ B $ ($ service_curr [$ I]. Name) \ B"
$ Pattern_state = "^ \ B $ ($ service_curr [$ I]. State) \ B"
# $ Pattern_name # Check Variables
# $ Pattern_state # Check Variables
$ Flag = 0
For ($ J = 3; $ J-lt $ filebase. length; $ J ++)
{
If ($ filebase [$ J]-match $ pattern_name)
{$ Flag = 1
# $ Filebase [$ J] # Check Variables
If (-not ($ filebase [$ J]-match $ pattern_state ))
{
$ Service_error + = "$ ($ service_curr [$ I]. Name) 'n"
# $ Service_error.length # Check Variables
Break
}
Else
{
Break
}
}
}
If ($ flag-EQ 0)
{
Write-host "$ ($ service_curr [$ I]. Name) This item is not found in servicebase"
}
}
$ Service_error
Compare powershell with the baseline services list to check whether the service status has changed