The PowerShell Podcast

Building your career with PowerShell

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 "

Episode 10 – WinRM will power PowerShell Remoting in V2

A Podcast about Windows PowerShell.
Listen:
Introduction

  • We’ve had over 5,400 downloads so far! Thanks, everyone!

News

  • PowerShell remoting will work via WinRM according to thisfrom the Scripting NewsWire
    • “Something else to consider. Sometime before the end of the year an upgraded CTP (Community Technology Preview) version of Windows PowerShell will be released, an upgrade that will enable you to run most Windows PowerShell cmdlets against remote computers. The catch? This new version of Windows PowerShell also relies on WinRM as its remote transport protocol. If you”™re interested in using Windows PowerShell to manage remote computers you"™ll need to download and install WinRM on your Windows XP and Windows Server 2003 machines."
  • New Blog: PowerShell Pro
    • “PowerShell Pro is a community devoted to compiling the leading resources needed in achieving that goal. Whether you are an advanced PowerShell user or just starting out, PowerShell Pro is dedicated to presenting information required for your success.”
    • Lots of content. Nice format.
  • Powershell “Yahoo Pipe”created by Jaykul.
    • Aggregate RSS feed containing articles from tons of PowerShell blogs.
  • Another company “Gets it”: IBM
    • Dale Lane in the UK has written on his blog about PowerShell Cmdlets he’s developing for IBM WebSphere.
  • Overview of next PS Virtual User’s Group - Dec 4th
    • Oisin presenting talk about cmdlet development, new foundations in pscx, and touching on providers
      and paths in PowerShell

Cmdlet of the week: Set-PSDebug
Check out Keith Hill’s article on Set-PSDebug: Effective PowerShell Item 5: Use Set-PSDebug -Strict In Your Scripts - Religiously

Episode 9 – PowerShell V2 news is coming in November

A Podcast about Windows PowerShell.
Listen:
Introduction

  • Thanks to //o// and Kirk at Poshoholic for mentioning us on their blogs. We loved Kirk’s post about namespaces with the Star Trek references.  That’s the Trouble with Tribbles!

News

  • According to Bruce Payette in this post, details of PowerShell V2’s upcoming features will be released in November at ITForum!
  • From <$hay@Israel’> s blog: There is a new book titled “Windows PowerShell in Practice” that is being worked on by Jim Truher and //o//.  It will be published by Manning and will cover topics such as, the PowerShell SDK (writing cmdlets, providers etc) advanced scripting techniques and domain specific examples.
  • Citrix, Citrix, and more Citrix!  Brandon Shell has gifted us with a veritable cornucopia of sixteen (16!) Citrix management functions such as:
    • Get-CitrixFarm
    • Publish-CitrixApplication
  • Keith Hill and //o// will be a guest speaker in the first Windows PowerShell Virtual User Group Meeting (From Marco Shaw’s blog)
  • Phoul from the #Powershell IRC channel has a new blog up(http://insecure-complexity.com/).  In his own words:
    • “Especially to the new PowerShell users. I’m writing a blog that will be focused around my findings in my experience learning PowerShell. It will have scripts and tutorials and some neat tips n tricks after I get a little more acquainted with PowerShell. For now it has a profile example and a useful script for signing your scripts.”

Cmdlet of the week

Episode 8 – Meet Hal Rottenberg!

A Podcast about Windows PowerShell.

- 


    **Introduction**








        Welcome to Hal Rottenberg! Check out his [blog](http://halr9000.com/)








- 


    **News**

Jeffery Snover interview

    - 

VMWare “gets it”! VI PowerShell blog

ex: Get-VM | where { $_.state -eq “poweredOn” } | Stop-VM

    - 

Post from $hay@Israel’s $cript Fanatic blog about Sapien

- 

Cmdlet of the week

select-object - BSonPoSH’s article on creating custom objects

and a follow up article

- 
  **

Resources **

Episode 7 – Don't Forget What You Already Know

A Podcast about Windows PowerShell.

- 

News

PowerShell Google group

  - 

Cmdlets of the week

New-item

      - 

Test-path

      - 

Get-WMIObject

MSDN WMI Reference

  - 

Resource

Windows PowerShell and WMI - Technet webcast w/ Don Jones

      - 

“Active Directory Management Made Easy with PowerShell” from Quest Software, link to Dmitry’s post

    - 
      Great [blog post](http://www.leadfollowmove.com/powershell-toolbox/) listing PowerShell tools







    - 

Tips

Episode 5 – PowerShell Hits a Million

A Podcast about Windows PowerShell.

- 

Introduction

Shout-out to Mark Allen for answering the challenge

- 

News

New AD cmdlets - the one step account creation works great

    - 

From the ScriptingNewswire, May 2007

Windows PowerShell guide for beginners

        - 

Downloadable and cmdlet-accessible graphical help for Windows PowerShell

    - 

/n software will be releasing NetCmdlets at TechEd next week

They are giving away free PowerShell stickers

Never Miss an Episode

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