Windows PowerShell Step by Step by Ed Wilson
Author:Ed Wilson [Wilson, Ed]
Language: eng
Format: azw3, pdf
Publisher: Pearson Education
Published: 2015-10-13T04:00:00+00:00
* * *
Note
If you are working with a service that has its startup type set to Disabled, Windows PowerShell will not be able to start it and will return an error. If you do not have administrator rights, Windows PowerShell will be unable to stop the service.
* * *
In the following exercise, you will explore the use of the Win32_Service WMI class by using the Get-WmiObject cmdlet as you retrieve service information from your computer.
Using WMI for service information
1. Start the Windows PowerShell console.
2. From the Windows PowerShell prompt, use the Get-CimInstance cmdlet to obtain a listing of all the services and their associated statuses. Use the gcim alias instead of typing Get-CimInstance. The command to do this is shown here.
gcim win32_service
A partial listing of the output from this command is shown here.
Click here to view code image
ProcessId Name StartMode State Status ExitCode
--------- ---- --------- ----- ------ --------
0 AJRouter Manual Stopped OK 1077
0 ALG Manual Stopped OK 1077
0 AppIDSvc Manual Stopped OK 1077
940 Appinfo Manual Running OK 0
0 AppMgmt Manual Stopped OK 1077
0 AppReadiness Manual Stopped OK 1077
3. Use the Sort-Object cmdlet to sort the listing of services. Specify the state property for the Sort-Object cmdlet. To sort the service information based upon the state of the service, pipeline the results of the Get-CimInstance cmdlet into the Sort-Object cmdlet. Use the sort alias for the Sort-Object cmdlet to reduce the amount of typing. The results are shown here.
Click here to view code image
gcim win32_service | sort state
Partial output from this command is shown here.
Click here to view code image
ProcessId Name StartMode State Status ExitCode
--------- ---- --------- ----- ------ --------
1448 MpsSvc Auto Running OK 0
992 vmickvpexchange Manual Running OK 0
972 vmicrdv Manual Running OK 0
324 lmhosts Manual Running OK 0
656 LSM Auto Running OK 0
4. Use the Get-CimInstance cmdlet to produce a listing of services. Sort the resulting list of services alphabetically by DisplayName. To do this, use the Sort-Object cmdlet to sort the listing of services by the name property. Pipeline the object returned by the Get-CimInstance cmdlet into the Sort-Object cmdlet. The command to do this, using the sort alias for Sort-Object, is shown here.
Click here to view code image
gcim win32_service | sort DisplayName
Notice that the output does not appear to actually be sorted by the DisplayName property. There are two problems at work. The first is that there is a difference between the name property and the DisplayName property. The second problem is that the DisplayName property is not displayed by default. Partial output of this command appears here.
Click here to view code image
1448 BFE Auto Running OK 0
0 BDESVC Manual Stopped OK 1077
0 wbengine Manual Stopped OK 1077
0 bthserv Manual Stopped OK 1077
0 PeerDistSvc Manual Stopped OK 1077
940 CertPropSvc Manual Running OK 0
0 ClipSVC Manual Stopped OK 0
5. Produce a service listing that is sorted by DisplayName. This time, use the Select-Object cmdlet to display both the state and the DisplayName properties. Use the gcim, sort, and select aliases to reduce typing. The command appears here.
Click here
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7769)
Filmora Efficient Editing by Alexander Zacharias(5810)
The Infinite Retina by Robert Scoble Irena Cronin(5289)
Learn Wireshark - Fundamentals of Wireshark. by Lisa Bock(3991)
Linux Device Driver Development Cookbook by Rodolfo Giometti(3935)
Edit Like a Pro with iMovie by Regit(3441)
Linux Administration Best Practices by Scott Alan Miller(2858)
Linux Command Line and Shell Scripting Techniques by Vedran Dakic & Jasmin Redzepagic(2837)
MCSA Windows Server 2016 Study Guide: Exam 70-740 by William Panek(2522)
Mastering PowerShell Scripting - Fourth Edition by Chris Dent(2412)
Docker on Windows by Stoneman Elton(2319)
Kali Linux - An Ethical Hacker's Cookbook: End-to-end penetration testing solutions by Sharma Himanshu(2315)
Creative Projects for Rust Programmers by Carlo Milanesi(2263)
Hands-On AWS Penetration Testing with Kali Linux by Karl Gilbert(2112)
Hands-On Linux for Architects by Denis Salamanca(2053)
Programming in C (4th Edition) (Developer's Library) by Stephen G. Kochan(2006)
Computers For Seniors For Dummies by Nancy C. Muir(2003)
The Old New Thing by Raymond Chen(1941)
Linux Kernel Debugging by Kaiwan N Billimoria(1763)
