#Input from File List of Computers $MyComputers=Get-Content 'C:\temp\MyComps.txt' #==================== #Instantiate Array #=================== $MyArray=@() $MyFails=@() #=============================== #Check Access to Each Computer #=============================== Foreach($Comp in $MyComputers){        If((Invoke-Command -ErrorAction SilentlyContinue –ComputerName $comp –ScriptBlock {1}) –eq 1){ $MyArray+=$Comp }Else{ $MyFails+=$Comp } } #--------------------------------------------- # Main Command to Execute on Remote Systems #--------------------------------------------- $MyCommand={ #For Storing Results $StartupResultsArray=@() #Create List of Services $ListofServicestoCheck=@('RemoteRegistry','WinRM','mpssvc') #==================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 { $_.name -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" }Else{ $StartupResultsArray+="$Service `t StartMode Failure" } }Else{ #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