Monday, August 27, 2012

Automated script to check the services in Automatic and Manual Mode

This week I am working on some new requirement from our Active Directory Architect to provide all the services required to start as "Automatic" and "Manual" for all my VMWare VDI infrastructure servers.

It is very painful to go to each server one by one to do this, so I written a simple Powershell script to check.

You will need to prepare for a text file (Servers.txt) which list all your servers you want to check. (One hostname in each line). This Servers.txt file should be in the same location as your service.ps1 script.

---start of service.ps1 script----------------------
$compArray = get-content .\Servers.txt
foreach($strComputer in $compArray)
{
echo $strComputer
echo --------------------------------------------------------------------------------------------------
Get-WmiObject Win32_Service -ComputerName $strComputer | Where {$_.StartMode -like "*Auto*"}| select-object DisplayName,Name,StartMode,StartName
echo --------------------------------------------------------------------------------------------------
Get-WmiObject Win32_Service -ComputerName $strComputer | Where {$_.StartMode -like "*Manual*"}| select-object DisplayName,Name,StartMode,StartName
echo --------------------------------------------------------------------------------------------------

}

---end of service.ps1 script----------------------

To run that script, you just need to login with an account with Local Administrator right for all servers needed and run the following command in the Powershell

.\services.ps1 | out-file results.txt

You will then see all services in results.txt.