Ezine 197 - Use PowerShell to Do Stuff You Cannot Do in a GUIEzine 197 - Use PowerShell to Do Stuff You Cannot Do in a GUIThe more reasons that you find to use PowerShell, the more likely you are to cope with the frustrations of learning something new, and come out the other side proficient at interrogating computers from the command-line. This week we are going to employ PowerShell to do stuff you cannot do with a GUI. We will also start using simple programming techniques to make the cmdlets even more useful. Topics for Learning PowerShell v 2.0 Commands
♣ This Week's SecretOne of life's mysteries is how do experts learn command-line languages. My bet is that for most scripting gurus formal training plays no part. While I had great satisfaction training Windows Server to techies, my DOS or VBScript classes never had the same feeling of success. Either the training came too late, the delegates new the stuff already, or they knew very little and lacked the desire and aptitude for configuring a computer by typing commands. My guess is that people learn scripting languages like DOS, VBScript and PowerShell, through copying other people's code from the internet, then reading books on how to modify what they have copied, topped off with a large dose of trial and error. My self-appointed mission is get people started. By giving you a few quick lessons, I want you to absorb enough of the basics to avoid frustration, and reach a level of competence where you can pursue your own branch of intermediate or even advanced PowerShell. This Week's Mission - Do Stuff You Cannot Do with a GUIOur task is to investigate the processes running on your computer. I have deliberately chosen some tasks that you cannot do with the Task Manager GUI. Incidentally, I bet that you will find at least one surprise in the list. I am guessing that you will spot a suspicious process that needs further investigation. This Week's Mission is also to use get-Service as a vehicle to reinforce the basics. For example, reap the benefits of get-Member, research with get-Command and remember that if all else fails: get-Help cmdlet name. As I constantly recommend, whenever you learn a new PowerShell cmdlet, try to open the corresponding GUI. That way you can understand what the script is doing, also the menus in the GUI give you ideas for improving the PowerShell code. In this instance open the Task Manager while you code with get-Process. Get-ProcessBefore we do stuff that you cannot do with the GUI, let's get acquainted with PowerShell's equivalent of the Task Manager: get-Process get-Process Another good reflex to develop is that whenever you see a new cmdlet, research its properties with get-Member get-Process | get-Member Note 1: Too much information? Filter by appending with -MemberType *property Note 2: If you don't understand how to 'append with
-MemberType property', then back to basics: Note 3: Remember where to use the pipe (|), e.g. before get-Member. And where you DON'T need a pipe, get-Help. Now for the stuff you cannot do with the GUI, let us group the processes by Company get-Process | sort-Object company ` Note 1: I admit to leaping ahead here and introducing three new techniques all at once. Sort-Object is self-explanatory, while piping (|) the output into format-Table allows us to control which properties to display. Finally -groupBy emphasises that some companies have multiple processes. Note 2: Please take the time to check the results and see if I am correct when I guess that at least one of YOUR processes is suspicious.
Guy
Recommends: WMI Monitor and It's Free!
| |||||
Custom Search
|
Guy Recommends: WMI Monitor and It's Free!
|
|
Home Copyright © 1999-2012 Computer Performance LTD All rights reserved Please report a broken link, or an error. | |