Subscribe / Unsubscribe Enewsletters | Login | Register

Pencil Banner

Go pro: The power user's guide to PowerShell

Woody Leonhard | Oct. 4, 2016
PowerShell is a powerful tool to master. Here’s our step-by-step guide to getting familiar with Windows’ über language

How to figure it out? Welcome to the get-member cmdlet. If you want to know what type of object a cmdlet produces, pipe it through get-member. For example, if you’re trying to figure out the processes running on your computer, and you’ve narrowed down the options to the get-process cmdlet, here’s how you find out what the get-process cmdlet produces:

get-process | get-member

Running that command produces a long list of properties and methods for get-process, but at the very beginning of the list you can see the type of object that get-process creates:

TypeName: System.Diagnostics.Process

The below screenshot also tells you that get-process has properties called Handles, Name, NPM, PM, SI, VM, and WS.

PowerShell TypeName

If you want to manipulate the output of get-process so that you can work with it (as opposed to having it display a long list of active processes on the monitor), you need to find another cmdlet that will work with System.Diagnostics.Process as input. To find a willing cmdlet, you simply use … wait for it … PowerShell:

get-command -Parametertype System.Diagnostics.Process

That produces a list of all of the cmdlets that can handle System.Diagnostics.Process.

Some cmdlets are notorious for taking nearly any kind of input. Chief among them: where-object. Perhaps confusingly, where-object loops through each item sent down the pipeline, one by one, and applies whatever selection criteria you request. There’s a special marker called $_. that lets you step through each item in the pipe, one at a time.

Say you wanted to come up with a list of all of the processes running on your machine that are called “svchost” -- in PowerShell speak, you want to match on a Name property of svchost. Try this PowerShell command:

get-process | where-object {$_.Name -eq "svchost"}

The where-object cmdlet looks at each System.Diagnostics.Process item, compares the .Name of that item to “svchost”; if the item matches, it gets spit out the end of the pipe and typed on your monitor. See the screenshot.

PowerShell svchost

Step 7: Dissecting a useful PowerShell command

At this point you know enough to shoot yourself (and your machine) in the foot. Be careful. Before I point you to further reading and drop you off the deep end, let’s go through an example of a PowerShell command that many of you have asked about.

This particular command works only in Windows 10 and only if you’re running PowerShell as an administrator. It’s designed to re-install the default Windows 10 apps, and I’ve found it useful for refreshing the little beasts -- particularly for those who deleted the built-in apps but suddenly have a change of heart. The command looks like this:


Previous Page  1  2  3  4  5  6  7  Next Page 

Sign up for CIO Asia eNewsletters.