Expand-Alias for PowerShell Integrated Scripting Environment   -   January 3rd, 2009

Get your PowerShell code ready for production by expanding your shorthand alias syntax.

Use the shorthand approach to knock out your scripts. Then expand them. Makes your code more readable and maintainable in the long run.

image  

 

 

 

 

 

 

Press Ctrl+Shift+E

image

 

 

 

 

 

 

 

How To

Add this code to your Microsoft.PowerShellISE_profile.ps1

Function Expand-Alias {
  $content=$psise.CurrentOpenedFile.Editor.text
  [System.Management.Automation.PsParser]::Tokenize($content, [ref] $null) |
    Where { $_.Type -eq ‘Command’} |
    Sort StartLine, StartColumn -Desc |
    ForEach {
      if($_.Content -eq ‘?’) {
        $result = Get-Command ‘`?’ -CommandType Alias
      } else {
        $result = Get-Command $_.Content -CommandType Alias -ErrorAction SilentlyContinue
      }

      if($result)
      {
        $psise.CurrentOpenedFile.Editor.Select($_.StartLine,$_.StartColumn,$_.EndLine,$_.EndColumn)
        $psise.CurrentOpenedFile.Editor.InsertText($result.Definition)
      }
    }
}

if( -Not ($psISE.CustomMenu.Submenus | ?{$_.DisplayName -eq ‘Expand Alias’}) ) {
    $null = $psISE.CustomMenu.Submenus.Add("Expand Alias", {Expand-Alias}, ‘Ctrl+Shift+E’)
}

Transactional Memory blog at MSDN   -   January 3rd, 2009

This blog is about transactional memory with entries written by the team at Microsoft that is implementing an experimental transactional memory system in .NET.

http://blogs.msdn.com/stmteam/default.aspx

Washing Machine that Twitters   -   January 1st, 2009

Ryan Rose hacks his appliance to send a message to Twitter when the laundry is done.

Follow it here.

Devices are getting plugged in.

Blogging, Transparency and PowerShell   -   December 30th, 2008

Jeffrey Snover, creator of PowerShell, blogged “I messed up” about his posts on the how to customize new PowerShell Editor features.

The team is releasing preview bits and they are in flux.

The code samples they’re blogging are crucial to the community gaining insight on what is coming.

That is great customer service. Check out the posts on the Integrated Scripting Environment

PowerShell and F#   -   December 30th, 2008

Two great tastes that taste great together. Andy Schneider posts how to use PowerShell’s Add-Type cmdlet to get at the FSharp Code Provider and inline F# text in a PowerShell script and then access it from PoSh.

Inline F# in PowerShell

PowerShell – Programmtically post and retrieve PowerShell code on your blog   -   December 30th, 2008

James Brundage, from the PowerShell team, has several posts up since the release of CTP3.

One is Write-CommandBlogPost another is The CodeDownloader Module.

I modified his Write-CommandBlogPost. Now I can post PoSh code and it can be pulled off my blog programmatically.

Additionally, I created a Microsoft Live Writer Plug-In, embedding  the PowerShell Scripting engine so with a few clicks I can inline my PoSh code in my WordPress blog post.

image

 

Sample PoSh Code

Write-Hello.ps1

Synopsis:

Writes Hello to the console

Syntax:

C:\PoSHScripts\Write-Hello.ps1 [[-who] [<Object>]] [<CommonParameters>]

Detailed Description:

Sample script writes Hello to the console

Examples:

--------------------- EXAMPLE 1 ---------------------

Write-Hello "World"

Command Parameters:


Name Description
who Who to say hello to

Here’s Write-Hello.ps1:

<#
.Synopsis
  Writes Hello to the console
.Description
  Sample script writes Hello to the console
.Parameter Who
  Who to say hello to
.Example
  Write-Hello "World"
#>

param($who)
"Hello $who"

Automatically generated with a custom version of Write-CommandBlogPost

Things you need

Download Live Writer C# Project.

You can download the Live Writer SDK and build the DLL, below is the Help About showing the version of Live Writer I am using.

Or copy the BlogPoSh.dll and Write-CommandBlogPost.ps1 from the bin/debug to C:\Program Files\Windows Live Writer\Plugins.

These steps are setup in the VS IDE for the project.

image

Upcoming Post

I will post the script that is ‘added’ to James’ Code Downloader which enables programmatic extraction the code above.

In James’ examples, he provides plug-in scripts that can programmatically download scripts from Microsoft PowerShell Blog posts and PoshCode.org.

Jingle Shell, Jingle Shell, PowerShell V2 CTP3 is RTW   -   December 23rd, 2008

via The PowerShell Guy

Download Windows PowerShell V2 CTP3

Download WinRM 2.0 CTP3 (required for PowerShell remoting)

Some New Things

  • Over 60 new cmdlets
  • Adding/Removing/Renaming computers
  • Cmdlets for event logs
  • Cmdlets for WS-Man functionality and even a WS-Man provider
Windows PowerShell ISE
  • Supports a graphical debugger
  • Context sensitive F1 help
  • A Programmable interface

via Hemant Mahawar Windows PowerShell Team

Advanced Functions

Cmdlets++ ?

Function Test-LeapYear {
  param( 
   [Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)] 
   [Int]$Year 
  ) 
}
 

Attributing parameters this way gives you

  • Ensures that you send it the right number of parameters
  • Supports pipelining
  • Tab-Completion of parameter names
  • Supports Get-Command, (Get-Command Test-LeapYear).Parameters

You can also provide granular inline documentation that works with Get-Help. Like Synopsis, Example, Link and more.

via Jeffrey Snover Windows PowerShell Team

I am really looking forward to working with PowerShell in 2009.

Microsoft Oslo - MGraph   -   December 22nd, 2008

Nice post on M, Quadrant and Repository via xosfaere. Here is a snippet.

Then we have MGraph. Now this is the simplest part because this is simply an abstract datamodel, just as the XML Information Set (Infoset) is for XML. It is a so-called labelled Directed Acyclic Graph (DAG) which means it is more structurally powerful than the tree-based Infoset model. MGraph is the result of a parse of an M instance file combined with an MGrammar file (you need the language syntax and MGraph mapping in order to create an MGraph out of an instance file). So this could be, for example a list of contacts in a text file and then the MGrammar file will specify the contact syntax and how it maps to an MGraph.

PowerShell: Querying Windows Desktop Search   -   December 21st, 2008

I saw this IronPython: Querying Windows Desktop Search.

Then took Lee Holmes’ Invoke-SqlCommand and hacked up Invoke-WDS 

param(
    $sqlCommand = "SELECT FileName FROM SYSTEMINDEX Where System.FileExtension =’.ps1′  Order By FileName"
)
 
$connectionString = "Provider=Search.CollatorDSO;Extended Properties=’Application=Windows’;"
 
## Connect to the data source and open it
$connection = New-Object System.Data.OleDb.OleDbConnection $connectionString
$command = New-Object System.Data.OleDb.OleDbCommand $sqlCommand,$connection
$connection.Open()
 
## Fetch the results, and close the connection
$adapter = New-Object System.Data.OleDb.OleDbDataAdapter $command
$dataset = New-Object System.Data.DataSet
[void] $adapter.Fill($dataSet)
$connection.Close()
 
## Return all of the rows from their query
$dataSet.Tables | Select-Object -Expand Rows

The Script Center has a deeper treatment here Seek and Ye Shall Find Scripting Windows Desktop Search 3.0

You can create queries like

@"
 SELECT 
  System.FileName 
 FROM 
  SYSTEMINDEX 
 WHERE 
  System.Music.Artist = ‘John Lennon’ 
 OR
  System.Music.Artist = ‘George Harrison’
"@

PowerShell is going to be the cluster scripting language for the future   -   December 20th, 2008

PowerShell for Failover Clustering in Windows Server 2008 R2

The team is looking for feedback on their current set of 68 cmdlets. They are using the new Module feature of PowerShell version 2.

To get a complete list of the cmdlets, run the following command: Get-Command -Module FailoverClusters

Example of creating a highly available File Server

$Node1 = "symonp-n1"
$Node2 = "symonp-n2"
$FileServerGroupName = "symonp-fsBlog"
$FileServerDiskResourceName = "Cluster Disk 1"
 
# Create a highly available file server
Add-ClusterFileServerRole `
 -Storage $FileServerDiskResourceName `
 -Name $FileServerGroupName

List of Verbs and Nouns

Verbs Nouns
  • Add
  • Block
  • Clear
  • Fail
  • Get
  • Grant
  • Move
  • New
  • Remove
  • Resume
  • Set
  • Start
  • Stop
  • Suspend
  • Test
  • Update
  • Cluster
  • ClusterAccess
  • ClusterAvailableDisk
  • ClusterDisk
  • ClusterDiskReservation
  • ClusterFileServerRole
  • ClusterGenericApplicationRole
  • ClusterGenericScriptRole
  • ClusterGenericServiceRole
  • ClusterGroup
  • ClusterIPResource
  • ClusterLog
  • ClusterNetwork
  • ClusterNetworkInterface
  • ClusterNode
  • ClusterOwnerNode
  • ClusterParameter
  • ClusterPrintServerRole
  • ClusterQuorum
  • ClusterResource
  • ClusterResourceDependency
  • ClusterResourceDependencyReport
  • ClusterResourceType
  • ClusterServerRole
  • ClusterSharedVolume
  • ClusterVirtualMachineConfiguration
  • ClusterVirtualMachineRole
Developed by DataDesignIT