Disaster Recovery – Get A List Of All Automatic Services Not Started

The following script contacts all the windows servers in the domain and returns a list of stopped services that are set to Automatic to a CSV file.

It also outputs to screen, servers it cannot contact or servers that are skipped as they are in the Excluded List

 

 

$ResultsFile = 'c:\temp\results.csv'
$ListOfserversInAD = get-adcomputer -filter {operatingsystem -like "Windows server*" } -properties operatingsystem,Whencreated,servicePrincipalName |sort-object -Property name
$oldverbosepreference = $VerbosePreference
$VerbosePreference = "continue"
$ExcludedList = "Server1",
                "Server2"
                

$results = foreach ($item in $ListOfserversInAD)
{
if ($ExcludedList -contains $item.name)
{
    Write-Verbose " $($item.name) in Excluded List"   
}
else
{
    


    try
    {
#get all services that are automatic and filter ones out you are not worried about
    Get-service -ComputerName $item.name -ErrorAction stop | where-object { $_.starttype -eq "Automatic" -and
                                                          $_.status -eq "Stopped" -and
                                                          $_.name -ne "RemoteRegistry" -and
                                                          $_.name -ne "clr_optimization_v4.0.30319_32" -and
                                                          $_.name -ne "clr_optimization_v4.0.30319_64" -and
                                                          $_.name -ne "TBS" -and
                                                          $_.name -ne "GxCVD(Instance001)" -and
                                                          $_.name -ne "GxEvMgrC(Instance001)" -and
                                                          $_.name -ne "GXHSM Recaller(Instance001)" -and
                                                          $_.name -ne "wuauserv" -and
                                                          $_.name -ne "SolarWinds Orion NCM Caching Service" -and
                                                          $_.name -ne "IKEEXT" -and
                                                          $_.name -ne "ShellHWDetection" -and
                                                          $_.name -ne "sppsvc"  }|
                                                          select * 
    }
    catch
    {
    Write-Verbose " $($item.name) cannot list services"
    }
}
}

$VerbosePreference =$oldverbosepreference 

$results |export-csv -path $ResultsFile

 

Leave a comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.