Windows PowerShell - WMI ServicesWindows PowerShell - WMI ServicesHere is a handy PowerShell script to investigate the operating system's services. While I focus on the Alerter service, you could easily modify the script to experiment with other Windows Services. Topics for PowerShell - WMI Services
♣ MissionPowerShell script to check whether a service is installed. If the service is present to report its status. Script 1 - The basic command# PowerShell script Script 2 - Introducing a $VariableThe idea here is to introduce PowerShell $Variable, and also to check the properties and methods with Get-Member cls Challenge Research other services, for example 'Print Spooler', 'Windows Shadow Copy' or 'Windows Time'. Script 3 - Introducing If.. Else Logic.Let us consider the possibility that the service is not installed; after all one, use of the script is to check service availability. What we are going to do is introduce 'If ... Else' logic. The exclamation mark ! checks for a null value for the service name. Should this if logic be true, then we declare ' This service is not installed on the computer', except we use a variable in place of 'This service'. # PowerShell script really mean: " + $sName }
PowerShell Learning PointsNote 1: -ErrorAction SilentlyContinue. If a script encounters a runtime error it displays a helpful error message, then continues. This switch or modifier merely suppresses that error message. Note 2: `n This grave accent (ASCII 096) followed by n tells the script to insert a carriage return. Note 3: PowerShell is particular about brackets Note 4: CLS is a quirk of mine, this old DOS command clears the screen, but you should not use it production scripts. Marco points out the following error with PrimalScript, which
is caused by CLS:
Guy Recommends: SolarWinds Engineer's Toolset v10
|
||||||
Download my ebook:
|
*
|
|
|
|
Home Copyright © 1999-2009 Computer Performance LTD All rights reserved Please report a broken link, or an error. | |