We recently released a beta of the PowerShell Community Extensions that supports PowerShell V2 in addition to V1.   This version also supports 64-bit versions of Windows.  The primary purpose of PSCX is to flesh out the functionality of PowerShell such that tools like cygwin and MKS Toolkit aren’t needed.  We aren’t completely there with PSCX yet but there is quite a bit of useful functionality in PSCX.  Here are some examples.

Enhanced CD function has browser like backwards and forwards history:

PS> cd $pshome;cd $pscx:home;cd $pscx:ScriptsDir;cd~

PS> cd

     # Directory Stack:
   — —————-
     0 C:\Users\Keith
     1 C:\Windows\System32\WindowsPowerShell\v1.0
     2 C:\Users\Keith\Pscx\Trunk\Src\PscxSnapin\bin\Debug
     3 C:\Users\Keith\Pscx\Trunk\Src\PscxSnapin\bin\Debug\Scripts
->   4 C:\Users\Keith

# Use cd – and cd + to move backwards and forwards through stack
PS> cd –

PS> cd +

# Or specify an entry number to jump to directly
PS> cd –1

# cd up several dir levels at once
PS> cd ….

Sending PowerShell output to the clipboard:

PS> Get-Process | Out-Clipboard

# The following uses the alias ocb and sets output width to prevent text truncation
PS> Get-ChildItem env: | ocb –width 9999

# To get the raw data without any PowerShell formatting
PS> $pwd | Write-Clipboard

Inspecting the contents of a file ala od.exe  (octal dump):

# View the first 16 bytes of powershell.exe
PS> Format-Hex $pshome\powershell.exe –count 16

Address:  0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F ASCII
——– ———————————————– —————-
00000000 4D 5A 90 00 03 00 00 00 04 00 00 00 FF FF 00 00 MZ…………..

# Using the fhex alias to inspect a text file to see if it has the UTF-8 BOM
fhex $pshome\FileSystem.format.ps1xml -count 48

Address:  0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F ASCII
——– ———————————————– —————-
00000000 EF BB BF 3C 3F 78 6D 6C 20 76 65 72 73 69 6F 6E …<?xml version
00000010 3D 22 31 2E 30 22 20 65 6E 63 6F 64 69 6E 67 3D ="1.0" encoding=
00000020 22 75 74 66 2D 38 22 20 3F 3E 20 0D 0A 3C 21 2D "utf-8" ?> ..<!-

Formatting XML:

# Ever have an XML string display as one long line, try this out
PS> "<a><b><c><d/></c></b></a>" | Format-Xml # Alias is fxml
      <d />

Testing XML for well-formedness and against a schema:

PS> "<a><b><c><d/></c></b></a>" | Test-Xml
PS> "<a><b><c><d/><c></b></a>" | Test-Xml -verbose
VERBOSE: The ‘c’ start tag on line 1 does not match the end tag of ‘b’. Line 1, position 19.

PS> $schemaPaths
C:\Program Files\Microsoft Visual Studio 9.0\Xml\Schemas\1033\Microsoft.Build.xsd
C:\Program Files\Microsoft Visual Studio 9.0\Xml\Schemas\1033\MSBuild\Microsoft.Build.Core.xsd
C:\Program Files\Microsoft Visual Studio 9.0\Xml\Schemas\1033\MSBuild\Microsoft.Build.CommonTypes.xsd

PS> Test-Xml .\ConsoleApplication1.csproj -SchemaPath $schemaPaths

Applying a XSL transform to a file:

PS> Convert-Xml My.xml –XsltPath My.xsl –EnableScript

There is a lot more functionality in PSCX such as the ability to create, read and expand ZIP and TAR files.  But that is enough of a teaser for this post.  Stay tuned for more info on what’s in PSCX.

This entry was posted in PSCX. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s