Hi Folks, have you heard that there are many ways to achieve something with PowerShell?
That’s indeed true we only need to take in consideration how big is our script and how much interaction the script will do in your system because it can cause loops, resources consumption and in the end, there is a proper way to do it and you must follow that standard.
Getting properties of Windows service that is set to Automatic and it’s currently stopped
PS C:\Windows\system32> Get-WmiObject -class Win32_service | Where-Object -Property StartMode -EQ -Value Auto | Where-Object -Property state -EQ -Value Stopped | Format-Table
ExitCode Name ProcessId StartMode State Status
-------- ---- --------- --------- ----- ------
1067 Automaton 0 Auto Stopped OK
0 gupdate 0 Auto Stopped OK
0 MapsBroker 0 Auto Stopped OK
0 RemoteRegistry 0 Auto Stopped OK
0 sppsvc 0 Auto Stopped OK
0 TrustedInstaller 0 Auto Stopped OK
0 WbioSrvc 0 Auto Stopped OK
0 wuauserv 0 Auto Stopped OK
PS C:\Windows\system32> Get-Service | Where-Object {$_.Status -eq 'Stopped' -and $_.StartType -eq 'Auto'}
Status Name DisplayName
------ ---- -----------
Stopped Automaton EMC SolVe Automaton
Stopped gupdate Google Update Service (gupdate)
Stopped MapsBroker Downloaded Maps Manager
Stopped RemoteRegistry Remote Registry
Stopped sppsvc Software Protection
Stopped TrustedInstaller Windows Modules Installer
Stopped WbioSrvc Windows Biometric Service
Stopped wuauserv Windows Update
Do you agree both achieve the end result but which one is better?
Here is a nice post about some best practices when scripting! Have fun
Leave your comments, cheers, Michael
0 Comments