Ezine 180 Three Commands to Get Started with PowerShellEzine 180 Three Commands to Get Started with PowerShellEach Ezine, has two purposes, firstly, to provide help when you have a problem understanding one of PowerShell's building-blocks, secondly, to provide interesting examples for those running PowerShell through its paces.
This Week's Secret - 3 Ways to Learn PowerShellThere are two main ways that people learn a programming language. Some simply copy and paste other people's scripts, while others undertake a course of structured programming methodology. I offer, and indeed specialize in a third way - project based learning. The idea is to learn PowerShell through a series of modules, each of which tackles a real-life task. One reason that PowerShell is suited to this learning approach is that its easy-to-understand commands deliver a big punch in just a few words. To take an example type, (or copy and paste!) get-Process. If you warm to the theme of project based learning, then what tends to happen is that you learn all about a narrow range of PowerShell structures needed to complete that particular task. The benefit is that when you tackle your second project there will be a carry-over of techniques that you learnt from your previous project(s). The secret of learning PowerShell quickly is to choose projects that are worthwhile, and here is where I can help with a free bank of material on my website. My mission is to provide lots of short examples that are simple to modify, yet have detailed explanations of what PowerShell is doing. This Week's MissionThe main purpose of this ezine is to explain that you need to know only 3 commands or techniques to get started with PowerShell. To stay true to my principles, this week I have also included a real-life mission to investigate the operating system's processes. Let us imagine that you suspect malware has invaded your operating system, and you need a list of processes so that you can eliminate them, else research their name on the internet as being a possible virus. Pre-RequisitesBefore you test my short scripts you need to download and install PowerShell and .Net Framework. Next you launch the executable 'PowerShell', now you are ready to type (or copy and paste) my short scripts. PowerShell's Three Learning ToolsOne way of looking at these three techniques is that these are the ONLY commands you need to get started with PowerShell. Furthermore, even professionals use these commands if they get stuck.
get-Help The secret of using get-Help is that precedes the cmdlet that you are investigating. I also have a tip: remember to include the -full parameter. Here are two examples: # PowerShell example to list demonstrate get-Help get-Help get-Process # (Not get-Process get-Help) get-Help get-Process -full get-Command The most obvious way to modify or filter the output is simply to add the first letter followed by the wildcard * symbol. # PowerShell example to list demonstrate get-Command get-command s* Other parameters which fine tune the list of cmdlets are -verb and -noun for example: # PowerShell example to list demonstrate get-Command -verb get-command -verb set # or get-Command -noun service get-Member (alias gm) The benefit of get-Member is that it lists the properties and methods of the cmdlet under investigation. If you take get-Process as an example, without appending get-Member you may not be aware of properties such as company, PriorityClass, StartTime. The trick with get-Member is to precede it with a pipe | thus: # PowerShell example to list demonstrate get-Member get-Process | get-Member # (And not get-Process get-Member, where we forgot the pipe) Tip. Employ the parameter -memberType, for example to filter only the properties try: get-Process | get-Member -memberType property From the results of get-Member you can design your own format for the output thus: get-Process | format-Table name, Company, PriorityClass, StartTime -auto Guy Recommends:
The Free IP Address Tracker (IPAT)
| |||||
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. | |