top of page

PowerShell | Services Startup Mode

This script is used to contact remote systems and verify the list of supplied services have the  startup mode set to automatic and if not change it.


#Input from File List of Computers
$MyComputers=Get-Content 'C:\temp\MyComps.txt'
#Instantiate Array


#Check Access to Each Computer

Foreach($Comp in $MyComputers){       
If((Invoke-Command -ErrorAction SilentlyContinue –ComputerName $comp –ScriptBlock {1}) –eq 1){

Main Command to Execute on Remote Systems

#For Storing Results
#Create List of Services
#==================Loop Through Services to Set Startmode to Automatic===================
Foreach($service in $ListofServicestoCheck){
#Get Service Info
$WMI = Get-WMIObject -class win32_service -namespace root\cimv2  | where-object { $ -eq $service } 
#Check if Service Already Set to Auto Start
If($WMI.StartMode -ne "Auto"){        
#If Not Set to Auto, Change it
$Return = $WMI.changestartmode("Automatic") 
#Check to See if Error Returned
if($Return.returnvalue -eq 0){
$StartupResultsArray+="$Service `t StartMode Success"
$StartupResultsArray+="$Service `t StartMode Failure"

#Message if Service Already in Automatic Startup Mode
$StartupResultsArray+="$Service `t StartMode Already Set"
Return $StartupResultsArray
#End Main Command 
#Execute Main Command And Export Results to Screen
Invoke-Command -ComputerName $MyArray -ScriptBlock $MyCommand

bottom of page