O'Reilly logo

Windows PowerShell™ Scripting Guide by Ed Wilson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using Decision-Making Statements

The ability to make decisions to control branching in a script is a fundamental technique. In fact, this is the basis of automation. A condition is detected and evaluated, and a course of action is determined. If you are able to encapsulate your logic into a script, you are well on your way to having servers that monitor themselves. As an example, when you open Task Manager on the server, what is the first thing you do? I often sort the list of processes by memory consumption. The GetTopMemory.ps1 script, shown here, does this.

Example 2-8. GetTopMemory.ps1

Get-Process |
Sort-Object workingset -Descending |
Select-Object -First 5

The GetTopMemory.ps1 script might be useful because it saves time in sorting a list. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required