Windows PowerShell Vista

Windows PowerShell for Vista Introduction

My mission is to help you install Microsoft’s PowerShell on Vista.  Once you have installed PowerShell, the first task is to set the script execution policy:

  1. Help Set-Executionpolicy
  2. Set-Executionpolicy remotesigned
  3. Get-Executionpolicy

Windows PowerShell Vista

Introduction to Windows PowerShell Vista Topics


7 Things To Get You Started With PowerShell

  1. Where to Download PowerShell (Get OS specific version)
  2. Begin with the old dos commands (dir, CD, Ipconfig) – Just to get comfortable
  3. Look for the Verb-Noun Pair (Set-executionpolicy)
  4. Call for help (Get-Help wmiobject)
  5. Create Scripts (Cmdlets)
  6. Deploy Pipe symbol | (Join commands | filter)
  7. Master $_.  It means the current object in the pipeline. (Where {$ -Contains "Microsoft})

How to Launch PowerShell in Vista

  • Download the correct version of PowerShell from Microsoft’s site.  Naturally for Vista, choose the Vista x86 or x64 version and avoid XP or Windows Server 2003 versions.
  • Install the PowerShell file with the .msu extension, mine was called:
  • Find the PowerShell file!  I tried Search ‘PowerShell’.  This revealed a shortcut to the executable in this folder:
     Start Menu –>  Programs –> Windows PowerShell ISE (v 2.0)
  • The underlying executable, called PowerShell.exe was found in:
     %Windir%\\System32\WindowsPowerShell\v1.0 (note the final sub-directory).
  • With PowerShell, my favorite thing to do, is to run cmdlets. These are nothing but PowerShell commands in a text file, but saved with .ps1 extension.
  • Problem 1: By default, you cannot ‘run’ or execute .ps1 files.  This script restriction for security reasons.
    Solution 1: You can change the ExecutionPolicy from restricted to RemoteSigned (best) or Unrestricted.
  • Problem 2: If you run PowerShell normally, you don’t have the permission (rights) to change the ExecutionPolicy.
    Solution 2: Run PowerShell as an Administrator.  It’s simplest to accept this rather than argue – that you are already logged on as THE ADMINISTRATOR.  What I do to get through this security restriction is:
    a) Create a shortcut to PowerShell.
    b) Right-click the shortcut, select Properties, Shortcut (tab) and then Advanced (button)
    c) Tick the box: Run as Administrator.
  • Launch PowerShell as Administrator, run this command:
    Set-ExecutionPolicy remotesigned  (note there is no minus sign in front of remotesigned).  See more on Set-ExecutionPolicy.
  • Now you can run cmdlets, which are those instruction files with a ps1 file extension.

Guy Recommends: Free WMI Monitor for PowerShellSolarwinds Free WMI Monitor for PowerShell

Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft’s 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. Give this WMI monitor a try – it’s free.

Download your free copy of WMI Monitor

Feel The Control of Vista’s PowerShellVista Powershell shortcut

In this section of my website I am going to focus on getting you started with Microsoft’s PowerShell.  Before I give you more examples, I want to say to developers and programmers that PowerShell has all the control and agility of languages such as perl, ruby and python.  One clue of PowerShell’s object nature is that you first need to install .NET Framework 2.0, otherwise PowerShell cannot work.  Above all else, PowerShell gives administrators the power and versatility of the UNIX Bash command line.

My most difficult concept to convey is an act of faith.  Trust me that PowerShell will deliver the goods and exceed your expectations.  Here is an example of what PowerShell could do; imagine this scenario: ‘One of my servers is running slower than the rest, can I check the version numbers of all the processes?’.  You are unlikely to find a built-in tool to answer this question, however, if you are expert in PowerShell you will be able to build cmdlets to answer this and similar operating system questions.

Programmers and developers will soon create scripts or cmdlets, yet my task is to persuade those with just server administration skills that they too can create code to interrogate the operating system.  Naturally, Admins will use the time-honoured tradition of copying other people’s scripts, indeed one of my goals is to create a bank of such cmdlets.  My greatest challenge is to provide a middle way, to persuade Admins that they can decipher the commands and easily modify the code to suit their own situations.

My Challenge – To Get You Started

My goal is to get you started with PowerShell.  My challenge is that in thirty minutes you will be able to perform all tasks that you currently achieve at the CMD prompt, and start issuing new PowerShell commands that are just not possible with CMD.EXE.

Assumption, you have successfully installed PowerShell and .NET Framework 2.0.  Begin by clicking Start, Run and type PowerShell, alternatively, create a short cut to PowerShell in the Quick Launch area.

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

SolarWinds’ Network 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.

What I like best is the way NPM suggests solutions to network problems.  Its also has 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 try NPM now.

Download a free trial of Solarwinds’ Network Performance Monitor

Try Out a Few PowerShell Commands

Normally, when people move to another scripting language their old trusty commands don’t work in the new shell.  Well, if you migrate from cmd.exe to PowerShell, then cd and dir are available thanks to Aliases.  In a short time, you adapt to the new ways of doing the same things.  For example, set-location is the equivalent of cd, and Get-Childitem the Alias for dir.  In addition, PowerShell allows you to run all the native Windows executables such as Ipconfig, Tracert and NetDiag.

The miracle of PowerShell is that thanks to Aliases, those coming from UNIX, perl or .NET can make a similar transition but employing their much more high powered commands.

Principle 1:  The heart of PowerShell is always a Verb-Noun pair.  You start with verb add a hyphen then finish with a noun.  For example, set-location is the equivalent to cd (change direcory) in DOS.  Incidentally, the reason cd works in PowerShell is because it has a built in Alias called cd which maps to set-location.  Good news, you can create your own aliases.

PowerShell Introduction – Simple Examples

I realize that these are Windows rather than Exchange 2007 examples but I want to get you up and running:
Preamble, Start, Run PowerShell.  In the dark blue shell type:

# PowerShell Vista
# or
Get-Eventlog system

Principle 2:  Create lots of scripts or cmdlets.  Save your text commands in a text file with a .ps1 extension, for example ProcessAll.ps1.  Moreover, save that file into PowerShell’s working directory.  Then execute these cmdlets from within the Microsoft Shell, for example:  .\ProcessAll.  Your two key characters are the dot and the backslash.  The secret is get into the rhythm: dot, backslash then filename.  There is no need to add the .ps1 extension, also avoid spaces.

If all else fails just type the complete path:
C:\Documents and Settings\GUYT\Documents\PSConfiguration\ProcessAll
(Or D:\scripts\ProcessAll)

Powershell tip - use tab for auto-completion  To save typing and risk making a spelling mistake use the Tab key to invoke auto-completion.

Auto-completion examples
Get-ev [tab] auto-completes to –> Get-Eventlog
set-lo [tab] auto-completes to –> set-location

Example of a PowerShell Cmdlet

# This cmdlet generates a report about memory in active processes

"Report generated at " + (Get-date)
"" # insert blank line

"High memory usage (>100000000)"

Get-Process | where-object { $_.VirtualMemorySize -gt 100000000 }


Help For PowerShell in Vista

All that PowerShell v 1.0 had was the command-line.  However PowerShell 2.0 has the ISE, my best tip is to seek out this GUI version.

PowerShell’s help is clear, concise and full of useful examples.  Put your faith in PowerShell’s help.  Cast aside negative experiences of other help files.  Overcome your pride and ask for help.  All you need to query the vast help information store, is either precede the item with ‘help’, for example, help Get-Member; or else append -? for example, Get-Process -? (hyphen question mark).  The executable powershell.exe even has its own help, at the PS prompt, type: powershell -?

Another useful sister cmdlet is: Get-Command, which lists the built-in cmdlets.  Better still, try the * wildcard:
Get-Command *service. 

Who is Windows PowerShell Designed For?


What impresses me about PowerShell is that even as an amateur, I can get going and create interesting scripts with ease.  The hidden message is that PowerShell works at many levels, moreover, you can easily rise through the levels.  In addition PowerShell teaches you about scripting theory, and scripting theory teaches you what to look for in PowerShell.

The vision of PowerShell is to provide cmdlets (scripts) which automate repetitive tasks.  There is a feeling, at least in Exchange 2003, that people cannot find settings because they are hidden underneath so many levels of sub-menus.  What I find is that with both Exchange and WMI cmdlets it soon becomes as fast to issue a few commands in the Microsoft Shell, as to configure the same settings through a GUI.

Admins who want a command line shell for interactive scripting will enjoy PowerShell.  The most amazing feature of PowerShell is that it lets you think in previous language, while you figure out its native ways of operating.  Creating new Aliases or using the built-in Aliases is the key to this transition.

PowerShell Vista Overview

The secret of PowerShell is to put commands in a file (cmdlet) and then forget them until the next time you need their automation.  With PowerShell you can manipulate text objects in an advanced manner.  You also get access to data stores which can be accessed as namespaces, for example, WMI and the Registry.

Consistency is a watchword, learn a verb in one area, then apply it to other PowerShell objects. For example, once we learn the verb ‘Stop’, there will never be a need to deviate, we don’t suddenly change to ‘kill’ or ‘terminate’

PowerShell supports COM, WMI, ADSI .NET XML.  Also unified tools from C++ C# and perl.  Naturally it supports Sub Routines, Constraints and utilities, for example: foreach, group, select, sort and where.

It is claimed that MMC v 3 and the Exchange 2007 System Manager will have the ability to auto-generate PowerShell scripts.  The catch phrase is: ‘Figure out, then manipulate’.

After I got PowerShell installed and when I had mastered a few simple commands, I listened to two 90 minute Microsoft Webcasts of PowerShell.  If I had listened to the presentation first, I would not have gone any further, I would have thought, ‘PowerShell is too difficult for non-programmers like you Guy’.  So my message is suck it and see, just try some of my examples, you will be amazed how easy it is get going with PowerShell.

However, there was a very important hidden message in that presentation, it was saying to me, ‘This is a seriously powerful scripting language’.  The speaker explained how PowerShell could do stuff that people now do in UNIX, perl, C++ or Visual Basic.  One day I will return that presentation because there is so much for me to learn about scripting principles in general and objects in particular.

Summary of PowerShell Introduction

With Microsoft’s PowerShell the underlying philosophy is to provide powerful scripts to automate occasional tasks. Furthermore, PowerShell is designed to make it easy for people to transition from other languages.  Trust me, it really is easy to get started with PowerShell commands.

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


See more Windows PowerShell tutorials

PShell Home   • Introduction   • Dreams   • 3 Key Commands   • PowerShell Help About   • Get-Help

PowerShell v 3.0   • Set-ExecutionPolicy   • Get-Command   • Cmdlet scripts   • Import-Module

PowerShell Version Check   • Backtick   • PowerShell examples   • PowerShell ISE   • Get-Member

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.