The PowerShell Podcast

Building your career with PowerShell

Episode 16 – Don gives us the Scripting Answers

A Podcast about Windows PowerShell.
Listen:

In This Episode

  • Special guest this episode is scripting guru Don Jones, the well-known author of several books, presenter and trainer at conferences and in webcasts and a lot more.
  • Several interesting tips for your scripting

Resources

  • We go into the history of PowerShellCommunity.org and future plans for the site. We also go into detail on the sections of the website and the mission of the non-profit organization behind it all.
  • Don gives the last holdouts a really hard sell for learning PowerShell.

Tips

  • Huddledmasses.org: Editing Media Tags from PowerShell
    • This started out as a question on the #PowerShell IRC channel (irc.freenode.net) about how to edit tags on mp3 files, but we quickly discovered TagLib#, which lets you access and edit tags on not only mp3s, but on everything from asf and avi to wma…
  • PowerShell Team: Supporting -Whatif, -Confirm, -Verbose ““ In SCRIPTS!
    • J. Snover: “This is a super-important issue so you should definitely start using this in your scripts that you share with others (that have side effects on the system). Please try it out and blog about it to others so that it becomes a community norm.”
  • $cript Fanatic: Creating and managing processes in PowerShell
    • Shay covers several ways to create and manage processes. WMI, .NET and more. Good stuff.

We ran long with Don, so combined with the slow news cycle for the holidays we just skipped the news this time.
Don’t forget–we love feedback. In particular we’d like to know if you like the guests, or do you like more of the one vs. one approach? It’s a lot of fun to have guests on the show and to do the special interviews and segments. Please let us know if this is getting to be too much or any other thoughts you may have. If you have ideas on guests you’d like to hear, let us know.
Ways to interact with us:

Specops Command Webinar

Corey from Special Operations Software wrote to let us know about a webinar demo of Specops Command that’s coming up next week. Here’s the details:

I wanted to let you know about a webinar we will be doing every Tuesday 1PM EST on the Specops Command “PowerShell Remoting through Group Policy”. Here are the meeting details if you are interested:
Click here to add the meeting to your calendar.

Episode 15 – Joel Bennett, for the developers in the house

A Podcast about Windows PowerShell.
Listen: [][1]

In This Episode

  • Special guest this episode, Joel Bennett aka “Jaykul” from [HuddledMasses.org][2]
  • “The Developer Show”
  • New software releases, interviews, other goodies

News

  • [AD Cmdlets RTM][3] (Dmitry"™s PowerBlog)“We kind of kept sticking to the fashion of perpetual betas for quite some time now (since the first 1.0 beta released late March through the RC 1.0.5 this fall) and we feel that the product is now feature rich and stable enough…”
  • [Windows PowerShell Holiday Gift Guide: Books][4] (Technet Scripting Center)“The Scripting Guys present their first-ever Windows PowerShell Holiday Gift Guide. In this inaugural gift guide we survey some of the best PowerShell software, script editors, cmdlets, and add-ins that money can buy.”
  • [An Interview with Lee Holmes][5] (Technet Scripting Center)“Lee Holmes is a developer on the Windows PowerShell team and author of the new book Windows PowerShell Cookbook (which includes a foreword written by Scripting Guy Dean Tsaltas).”
  • [An Interview with Lee Holmes][6] (A Couple of Admins Podcast)
  • [Cisco opening up IOS][7] (Network World)“Cisco’s plan to open up its venerable IOS routing software to customers and third-party developers is a bold move designed to further the company’s push to make the network the epicenter of the virtual data center.”

Resources

  • [Expresso Regular Expression Development Tool][8]Very cool tool to create regexes.  Free registration required.[image][8]

Tips

  • Discussion on an email from listener John Cook:

“I’m a programmer, so I don’t find PowerShell (or VBScript etc.) difficult as a language. What I find difficult about scripting is scripting itself, such as recognizing when it’s worth the effort to write a script. I’m a big fan of scripting, but I don’t write a lot of scripts because I don’t think to do it. Or I’m doing something that’s not repetitive enough to script.
I would find it interesting to listen to a show about scripting strategy: organizing tasks so they can be scripted, etc.
I would also find it interesting to hear a discussion about testing scripts. I’m a fan of test-driven development, but scripts are hard to test. Scripts are full of side effects: creating or deleting files, setting properties, sending email, etc.”

Manipulating the Registry with PowerShell

In case you missed it, back in October, Shay wrote a cool set of functions for working with the registry. Here’s the list:
Get-RegBinary
Get-RegDWord
Get-RegDefault
Get-RegExpandString
Get-RegMultipleString
Get-RegQuadWord
Get-RegString
Get-RegValueKind
New-RegSubKey
Remove-RegSubKey
Remove-RegSubKeyTree
Set-RegBinary
Set-RegDWord
Set-RegDefault
Set-RegExpandString
Set-RegMultipleString
Set-RegQuadWord
Set-RegString
Test-RegSubKey
Test-RegValue
Go read his article as it explains the syntax and gives a bunch of samples. Very useful stuff!

Episode 14 – The IDEs are getting better

A Podcast about Windows PowerShell.
Listen:

In This Episode

  • News: Software updates, books, PS Virtual User Group (recording will be available)
  • In Resources, we’ll tell you about an interview with Jeffrey Snover, and several pieces of software.
  • Cmdlet of the Week: New-Object
  • In Tips, we’ll talk about Hal’s recent blog post involving benchmarking
  • We’ve got a one-liner with a GUI.
  • Gotchas about WMI
  • Thanks for feedback from: Mace, John Cook, Justin Stokes

News

  • PowerShell + is now free for non-commercial use!
  • PowerShell TFM (2nd Edition)to be available soon - May be available already from the Sapien site
    • Don says Sapien tends to run some insane deals on New Years Eve so it may be worth watching out for that
  • PowerShell Virtual User Group meeting #2 was Dec 4th - This was the second virtual event.  Speakers were: Don Jones (MVP), Dmitry Sotnikov (MVP), Oisin Grehan and Jeffrey Snover (Microsoft).  Recording is supposed to be available, but as of this moment, Hal can’t find a darn thing about it.  Watch Marco’s blog and PowerShellCommunity.org.

Resources

Cmdlet of the week

  • New-Object
    • Creates an instance of a .Net or COM object.
    • Examples:

new-object -comobject InternetExplorer.Application  new-object -comobject "Shell.Application" * Also see Appendix E of the new book Windows PowerShell Cookbook

Episode 12 – Our first guest, Brandon Shell

A Podcast about Windows PowerShell.
Listen:

Introduction

  • Jam-packed show today! We ran so long, we had to skip the cmdlet-of-the-week segment!
  • We have a Special Guest, and in fact our first guest, Brandon Shell, an MVP in Automation and author of the BSonPosh blog.

News

  • CTP!
  • Citrix “Gets it”
    • As pointed out by Dmitry and others, “From a management standpoint, Citrix is getting high on PowerShell and intend to rewrite the APIs to make everything available from Powershell scripting.
  • Windows PowerShell Virtual User Group Meeting #2
    • Time: December 4th, 2007 at 12PM (noon) EST (New York time)
    • Registration site:http://www.clicktoattend.com/?id=122431
      Event Code: 122431
    • Guests: Don Jones (MVP), Dmitry Sotnikov (MVP), Oisin Grehan and Jeffrey Snover (Microsoft)

Resource

Tips

  • More VMWare scripting: Invoke-VmCommand.ps1from Brandon
    • List VMs and processes, execute arbitrary commands.
  • Talk about Switch -regex and Brandon’s perfect exampleof a useful custom object
    • Why write a wrapper for this existing utility? (hbainfo)
    • Using Switch -regex to process text
  • Marcus asks (and he blogged about it),
    • “How can I fix formatting on a free-form street address field stored in my AD? Can posh help with an output where … for example, address is split into multiple lines? Like this:
      “400 crap rd,
      suite 150”
    • Ended up using calculated properties to get the results into a table easily:

$a | format-table displayname,samaccountname, @{ Label =“Street Address” ; Expression = {

Creating and using custom objects

Listener Mace writes:

I’ve seen this code:

$values = new-object ‘object[,]’ 5,2
Can you expound on that?
The author fills the array.
$k = 0
foreach ($j in $exchangeserverlist)
{
$perf = New-Object System.Diagnostics.PerformanceCounter($perfobj1,
$counter1, $instance1, $j.Name)
$values[$k,0] = $j.Name
$values[$k,1] = $perf.RawValue
$k = $k + 1
}
Now, how do you sort the array based on the performance data in the second
column?
I’m guessing there’s a more “powershell” was of doing what’s needed rather
than resorting to arrays. E.g.,
$p = get-process
$p | sort-object ws
How would you create a collection of custom objects. Each custom object
would have two custom properties “exchangeserver” and “perfdata”.
{create the custom collection – somehow}
$co | sort-object perf

Get free disk space one-liner

Listener Bill writes,

I have been looking at the get-help and get-member cmdlets, but have so far not found one thing I want to have as a “one-liner” - a command line that will return the free space on a certain drive.

**""${env:computername}","" + (gwmi -Query "SELECT FreeSpace FROM Win32_LogicalDisk WHERE DeviceID = 'C:'").FreeSpace / 1GB + '"' | sc my.csv ** Got kinda ugly with the quote escaping. I'll explain... The concept here is to, in one line, build a string and then write it to a log file. First I write a quote to the string, because I chose to create it in CSV style. Had to escape it using the backtick character. Then I snag the computername from the env: virtual drive (or PSProvider). I had to use the curly braces around it because during variable substitution inside of a string, the colon can be a delimiter for setting scope on a variable so I wanted to tell it explicitly not to do that. We talk about this in Episode 11. Then more quotes and commas for the CSV format. Then I do a Get-WmiObject call. I felt like being fancy so I used a WQL query string which looks a lot like SQL. The query said to grab just one property from the Win32_LogicalDisk class where the ID is “C:”. Then access that property and divide it by 1 GB and add a closing quote. Pipe the whole thing to Set-Content and Bob’s your uncle.
Having said that, I wouldn’t do it this way. But it would work, I tested it.
Keep the feedback, and questions coming!
-hal

Episode 11 – A new PowerShell community

A Podcast about Windows PowerShell.
Listen:

Introduction

News

  • PowerShell Community (powershellcommunity.org)
    • “Real” non-profit organization created by corporate sponsors including Microsoft, Quest, Sapien, and ShellTools.
    • Event calendar, blog hosting, forums, etc.
    • Still under construction.
  • PowerShell Central (powershellcentral.com)
    • Hosted by BSonPosh and lots of help contributed by Jaykul.
    • “All PowerShell bloggers” aggregate news feed, very cool script repository, news, etc.
    • Still under construction. * Relaunch and refocus of Powershell Live (ShellTools) as well as a new developer blog. New features in development like context menus for collections and pipelines.

Resources

Tips

Cmdlet of the week

  • Write-Verbose
    • Use in parameter section of functions and combine with an If statement to enable or disable verbose logging.

Function Get-Foo { Param ( [switch] $Verbose ) If ($Verbose) { $VerbosePreference = “Continue” } Write-Verbose “My verbose stuff goes here Write-Verbose "

Never Miss an Episode

Subscribe to get the latest episodes delivered straight to your favorite podcast app.