One-Liner: GetDateTimeFormats

DateTime objects are amazing.  You can format them in so many different ways, but they also come with a boatload formats pre-defined.  Oh, and it uses the current culture.  So much cleaner.  But which is which? $i = 0; (Get-Date).GetDateTimeFormats() | Select-Object @{name = ‘index’; expression = {$i; $null = $global:i++ }}, @{name = ‘output’;…


PowerShell for Non-N00bs: LiveMeeting XML API and You

I work with Microsoft LiveMeeting regularly, and have found PowerShell’s ability to interact with its public XML API interface to be of great value.  There’s even a blog devoted to this topic (last update August 11, 2008 – it’s a stable interface, so there’s little change.) Here’s a scrubbed screen scrape of me getting my…


Powershell for non-N00bs: Creating XML the .NET Way

I’m dogmatic – if there is a ‘right’ way to do something, I want to do it (or at least learn how to do it) the ‘right’ way.   So often, I’ve seen [xml]$xml = “<xml />”; That’s one way to do it, but not the RIGHT way, dammit.  I want to use the constructor:…


PowerShell for Non-N00bs: Creating Shortcuts

$shell = new-object -com if($name)#create shortcut in same directory {      $shortcut = $shell.createshortcut(“c:\” + $name + “.lnk”) } Else #create shortcut in specified directory {      $shortcut = $shell.createshortcut($source + “.lnk”) } $shortcut.targetpath = $source if($Args -ne “”) #set arguments for shortcut {      $shortcut.Arguments = $Args } $


PowerShell Gotchas: Looping with $null

For some obscene reason, PSHv1 will gladly iterate with a $null as an array element in Foreach. @($null, 1, $null, 2) | Foreach { “‘$_'”; } ”’1””2’ So, in the name of defensive programming, I’ve taken to manually testing for this case: @($null, 1, $null, 2) | Foreach { if ($_) { “‘$_'”; } } ‘1”2’…