Prof. Powershell

PowerShell Pack

There are more than 800 functions and cmdlets, so start getting familiar with them.

As part of the Windows 7 Resource Kit, Microsoft is including the PowerShell Pack. This is a collection of almost 800 PowerShell 2.0 functions and scripts, organized into modules. You can download PowerShell Pack here. The MSI package will install everything to your home directory:

PS C:\> dir $home\documents\windowspowershell\modules

   Directory: C:\Users\Jeff\documents\windowspowershell\modules

Mode          LastWriteTime  Length Name
----          -------------  ------ ----
d----    10/16/2009 1:33 PM         DotNet
d----    10/16/2009 1:33 PM         FileSystem
d----    10/16/2009 1:33 PM         IsePack
d----    10/16/2009 1:33 PM         PowerShellPack
d----    10/16/2009 1:33 PM         PSCodeGen
d----    10/16/2009 1:33 PM         PSImageTools
d----    10/16/2009 1:33 PM         PSRSS
d----    10/16/2009 1:33 PM         PSSystemTools
d----    10/16/2009 1:33 PM         PSUserTools
d----    10/16/2009 1:33 PM         Setup
d----    10/16/2009 1:33 PM         TaskScheduler
d----    10/16/2009 1:33 PM         WPK
-a---    10/12/2009 4:23 PM   27680 About the Windows 7 Resource Kit Powe...
-a---    10/12/2009 4:23 PM    4791 Readme1st.txt
-a---    10/12/2009 4:26 PM  236247 Writing User Interfaces with WPK.docx

When you get a moment, be sure to read the documentation. But I expect you want to dive in. The scripts and functions are organized by module:

  • WPK: Create rich user interfaces quick and easily from Windows PowerShell. This goes beyond WinForms.
  • TaskScheduler: List scheduled tasks, create or delete tasks. The name says it all.
  • FileSystem: Monitor files and folders, check for duplicate files, and check disk space.
  • IsePack: Scripts for the Integrated Scripting Environment with over 35 shortcuts
  • DotNet: Explore loaded types, find commands that can work with a type, and explore how you can use PowerShell, DotNet and COM together
  • PSImageTools: Convert, rotate, scale, and crop images and get image metadata
  • PSRSS: Use the FeedStore from PowerShell, and I’m not talking about horses.
  • PSSystemTools: Get Operating System or Hardware Information
  • PSUserTools: Get the users on a system, check for elevation, and start-processaadministrator
  • PSCodeGen: Generates PowerShell scripts, C# code, and P/Invoke

Use Import-Module to load up one of these beauties.

PS C:\> get-module PSSystemTools

ModuleType  Name           ExportedCommands
----------  ----           ----------------
Script      PSSystemTools  {Test-32Bit, Get-USB, Get-OSVersion, Get-Mul...}

It’s a little hard from here to see what’s included so we’ll use Get-Command instead.

PS C:\> gcm -module PSSystemTools | ft CommandType,Name -auto

CommandType Name
----------- ----
   Function Get-BootStatus
   Function Get-DisplaySetting
   Function Get-Font
   Function Get-LogicalDiskInventory
   Function Get-MultiTouchMaximum
   Function Get-OSVersion
   Function Get-Processor
   Function Get-SystemFont
   Function Get-USB
   Function Get-WindowsEdition
   Function Import-IniFile
   Function Test-32Bit
   Function Test-64Bit

Even though these are functions and not cmdlets, they have been written as advanced functions that behave essentially as cmdlets. Very often they will include help:

PS C:\> help get-processor

NAME
Get-Processor

SYNOPSIS
Gets processor information for local and remote computers.

SYNTAX
Get-Processor [[-Computer] <Object>] [<CommonParameters>]

DESCRIPTION
The Get-Processor function gets information about the processors
on local and remote computers, including the processor architecture.

RELATED LINKS

REMARKS
To see the examples, type: "get-help Get-Processor -examples".
For more information, type: "get-help Get-Processor -detailed".
For technical information, type: "get-help Get-Processor -full".

That’s handy. Let me try it out:

PS C:\> get-processor

Architecture            : X86
__GENUS                 : 2
__CLASS                 : Win32_Processor
__SUPERCLASS            : CIM_Processor
__DYNASTY               : CIM_ManagedSystemElement
__RELPATH               : Win32_Processor.DeviceID="CPU0"
__PROPERTY_COUNT        : 48
__DERIVATION            : {CIM_Processor, CIM_LogicalDevice, CIM_LogicalElemen...
__SERVER                : GODOT7
__NAMESPACE             : root\cimv2
__PATH                  : \\GODOT7\root\cimv2:Win32_Processor.DeviceID="CPU0"
AddressWidth            : 32
Availability            : 3
Caption                 : x86 Family 6 Model 9 Stepping 5
ConfigManagerErrorCode  :
ConfigManagerUserConfig :
CpuStatus               : 1
CreationClassName       : Win32_Processor
CurrentClockSpeed       : 1598
CurrentVoltage          : 33
DataWidth               : 32
Description             : x86 Family 6 Model 9 Stepping 5
DeviceID                : CPU0
ErrorCleared            :
ErrorDescription        :
ExtClock                : 133
Family                  : 185
...

I truncated the output, but you get the idea. The function is returning a WMI object, which I probably could have done myself with Get-WMIObject, but the function saves me time and I can use it like I would a cmdlet:

PS C:\> get-processor | Select Name,Manufacturer

Name                                     Manufacturer
----                                     ------------
Intel(R) Pentium(R) M processor 1600MHz  GenuineIntel

The PowerShell Pack is loaded with goodies like this that will keep you busy for weeks to come. I can’t wait to dig in.

About the Author

Jeffery Hicks is an IT veteran with over 25 years of experience, much of it spent as an IT infrastructure consultant specializing in Microsoft server technologies with an emphasis in automation and efficiency. He is a multi-year recipient of the Microsoft MVP Award in Windows PowerShell. He works today as an independent author, trainer and consultant. Jeff has written for numerous online sites and print publications, is a contributing editor at Petri.com, and a frequent speaker at technology conferences and user groups.

comments powered by Disqus
Most   Popular