Guy recommends :
Free Solarwinds
VM Console

Solarwinds VM Console Free Download

Find out which of your VMs are a waste of space and which VMs need more resources.



What's New In Version PowerShell 2.0

Windows PowerShell 2.0 CmdletsWindows PowerShell Tutorial

PowerShell 1.0 has about 125 cmdlets, whereas v 2.0 has a minimum of 230.  The precise number depends on whether you are running Windows 7 or XP.

 ♣

PowerShell Transactions

On Vista and later on operating systems PowerShell supports database style 'ACID' transactions, whereby you can commit or roll-back a sequence of operations.

PowerShell Modules

Import-Module loads a bunch of dll and scripts, it replaces the Add-PSSnapin.   See more about the PowerShell modules directory.

#REQUIRES -version 2.0

This is not merely a remark, but an instruction to PowerShell v 1.0 that it cannot run the code which follows.

# PowerShell 2.0 Requires Example
# Requires -version 2.0
Enter-PSSession IpAddress or FQDM

Research Techniques for Finding New PowerShell 2.0 Cmdlets

One way of checking for new PowerShell 2.0 cmdlets is to use Get-command with the -noun or -verb parameter.  For example I heard a rumour there was a new measure cmdlet.

Research Measure-Object

# Research measure cmdlets
Clear-Host
Get-command -verb measure

Research New Event cmdlets

# Research new event Windows PowerShell 2.0 cmdlets
Clear-Host
Get-command -commandType cmdlet *Event*

Note: Get-WinEvent

List All Cmdlets

# Research new Windows PowerShell 2.0 cmdlets
Clear-Host
Get-command -CommandType Cmdlet

More New Windows PowerShell 2.0 Cmdlets

Guy Recommends: WMI Monitor and It's Free!Solarwinds Free WMI Monitor

Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft operating systems.  Fortunately, Solarwinds have created a Free WMI Monitor so that you can discover these gems of performance information, and thus improve your PowerShell scripts.  Take the guess work out of which WMI counters to use when scripting the operating system, Active Directory or Exchange Server.

Download your free copy of WMI Monitor

General Advice For PowerShell 2.0 and 1.0.

Four Reasons to Learn Windows PowerShell

  1. Think of learning PowerShell as a more convenient method of configuring the server than using the corresponding GUI.  I can foresee running PowerShell scripts that will diagnose server problems.  With PowerShell you can run queries that are not possible from the GUI.  On a good day such a script would even cure the problem - magic! 

    To come back down to earth, let us start with a trivial example to illustrate the capability of PowerShell.  As you may know, the Task Manager will display all the processes, yet with PowerShell you can not only list all processes, but also group them by company (Microsoft, HP and Roxio).  All you need is this one-liner:
    Get-Process | group-Object company
  2. PowerShell will achieve the same results as VBScript, but with fewer commands.  For instance, PowerShell makes scripting WMI much easier, for example, try: Get-WmiObject win32_BIOS.  More good news, you can even use PowerShell to replace VBScript for Active Directory scripts.
  3. I have a sense that there is a changing of the guard; out with old CMD commands, and in with new PowerShell language.  More importantly, the new PowerShell language will give you command line control of the Windows operating system; this is similar to the power that Bash commands exert over the UNIX operating system. 

    In a nutshell: PowerShell really is the way of the future.
  4. The main reason for learning PowerShell is so that you can administer Exchange Server 2007, and also the Longhorn server that will succeed Windows Server 2003.  Microsoft's thinking is that the point has arrived where complex products like Exchange and Longhorn have so many menus and sub-menus to configure via a GUI, that we need an alternative.  Hence the easy-to-use scripting language called PowerShell.

Note: Existing Windows executables, such as Ipconfig and ping, perform in the PS Shell just as they do in the old CMD 'DOS box'.

Guy Recommends:  A Free Trial of the Network Performance Monitor (NPM)Review of Orion NPM v10

Solarwinds' Orion performance monitor will help you discover what's happening on your network.  This utility will also guide you through troubleshooting; the dashboard will indicate whether the root cause is a broken link, faulty equipment or resource overload.

Perhaps the NPM's best feature is the way it suggests solutions to network problems.  Its second best feature is the ability to monitor the health of individual VMWare virtual machines.  If you are interested in troubleshooting, and creating network maps, then I recommend that you take advantage of Solarwinds' offer.

Download a free trial of the Network Performance Monitor.

Simple PowerShell Examples

Preamble, Start, Run PowerShell. 
At the command line type (In that dark blue shell):

Get-Service

Here is another example, type:
Get-WmiObject win32_computersystem

I first realised the ability of PowerShell when I saw three lines of PowerShell replace about twenty lines of VBScript.  The task is to interrogate Win32_classes, we can either use the traditional VBScript and WMI, or the new PowerShell with its verb-noun commands.

VBScript

 Windows PowerShell

' Memory.vbs
' VBScript to discover how much RAM in computer
' Author Guy http://computerperformance.co.uk/
' Version 1.3 - August 2005
' -------------------------------------------------------'
Option Explicit
Dim objWMIService, objComputer, colComputer
Dim strLogonUser, strComputer
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
For Each objComputer in colComputer
Wscript.Echo "System Name: " & objComputer.Name _
& vbCr & "Total RAM " & objComputer.TotalPhysicalMemory
Next

WScript.Quit

' End of Sample Memory WMI / VBScript

# Windows PowerShell script
# Displays ComputerName and memory
$CompSys = Get-WmiObject win32_computersystem

"System Name = " + $CompSys.name
"Memory = " + $CompSys.TotalPhysicalMemory

 

Summary of What's New In Windows PowerShell v 2.0

Remoting is the big new feature of PowerShell v 2.0 followed closely by the ISE which makes writing scripts so much easier.  Other than that, there lots of neat extra cmdlets.

If you like this page then please share it with your friends

 


See more PowerShell examples

PowerShell Home   • Foreach loops   • PowerShell Foreach   • Foreach-Object cmdlet

Syntax   • Variables   • -whatIf   • -ErrorAction   • Windows PowerShell   • PowerShell 2.0

PowerShell Functions   • [System.Math]   • Get-Credential   • Windows 7 PowerShell 2.0

Please email me if you have a better example script.  Also please report any factual mistakes, grammatical errors or broken links, I will be happy to  correct the fault.

Download my ebook:Getting Started with PowerShell
Getting Started with PowerShell - only $9.25

You get 36 topics organized into these 3 sections:
   1) Getting Started
   2) Real-life tasks
   3) Examples of Syntax.

In addition to the ebook, you get a PDF version of this  Introduction to PowerShell ebook  It runs to 120 pages of A4.

 *


Custom Search

Guy Recommends: WMI Monitor and It's Free!Solarwinds WMI Monitor

Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft operating systems.

Fortunately, Solarwinds have created the Free WMI Monitor so that you can actually see and understand these gems of performance information.  Take the guess work out of which WMI counters to use for applications like Microsoft Active Directory, SQL or Exchange Server.

Download your free copy of WMI Monitor

 

Home Copyright © 1999-2012 Computer Performance LTD All rights reserved

Please report a broken link, or an error.