Automating the world one-liner at a time…
I write a lot of scripts, and, since I blog some of what I write, my home computer has been running Windows PowerShell CTP2 since it came out. Since CTP3 has a number of changes from CTP2, I've got to update my home script library to work with CTP3. While this guide might not have every change that happened in between CTP2 and CTP3 (because I script with most, but not all, of PowerShell), I hope that this record of conversion steps helps everyone else moving from Windows PowerShell CTP2 to CTP3. Oisin Grehan has posted a fairly complete list of cmdlet name changes on his blog, Nivot Ink. This document only details what I've had to do to update my own scripts from CTP2 to CTP3, but not everything that has changed between the two releases.
Here's a list of all of the changes I've had to make to my personal script collection so far.
CTP2:
cmdlet ` -DefaultParameterSet Type `
CTP3:
[CmdletBinding(DefaultParameterSetName='Type')]
Note that it's DefaultParameterSetName, not DefaultParameterSet. In my script collection, this was the most tedious thing to change out.
# Create a runspace to run Hello World $rs = [RunspaceFactory]::CreateRunspace() $rs.ApartmentState, $rs.ThreadOptions = “STA”, “ReuseThread” $rs.Open() $psCmd = {Add-Type -AssemblyName PresentationCore,PresentationFramework,WindowsBase}.GetPowerShell() $psCmd.Runspace = $rs $psCmd.Invoke() $psCmd.Commands.Clear() $psCmd.AddScript({ $window = New-Object Windows.Window $window.Title = $window.Content = “Hello World. Check out PowerShell and WPF Together.” $window.FontSize = '24' $window.SizeToContent = “WidthAndHeight” $window.add_MouseDoubleClick({$this.Close()}) $null = $window.ShowDialog() }).BeginInvoke()
Once again, this is only the changes that I've made to my personal script collection at home. This post doesn't contain all that is new or cool with CTP3 (and there's a lot of new coolness in CTP3), but it does contain the changes that broke my CTP2 scripts that I am aware of. I will update as I make more changes, and, if you've had any issues converting your CTP2 scripts to CTP3, please post a comment to this blog and I'll update the conversion guide.
Hope this Helps,
James Brundage [MSFT]
Hey James!
While poking around CTP3 in reflector, I noticed that there are type accelerators for runspace and runspacefactory: [runspace] and [runspacefactory] respectively. This would shorten your ctp3 version just a little bit more ;)
- Ois
Thanks Oisin, I've updated the post.
- James
"Note that it's DefaultParameterSetName, not DefaultParameterSet. In my script collection, this was the most tedious thing to change out."
Should've written a script to do it. :-)
how comversion in downloads powershell ctp2 for ctp3 l would like make do