Show Us Your Cmdlets!

4 05 2008

This little one-liner will show the most common verbs among all the cmdlets installed in the current PowerShell session.

   1: PS > gcm -CommandType cmdlet | Group Verb | Sort Count -Descending | Select -First 10
   2: 
   3: Count Name                      Group
   4: —– —-                      —–
   5:   128 Get                       {Get-Acl, Get-ADObject, Get-Alias, Get-Authentico…
   6:    46 Set                       {Set-Acl, Set-Alias, Set-AuthenticodeSignature, S…
   7:    36 New                       {New-Alias, New-CDDrive, New-Client, New-Cluster,…
   8:    34 Remove                    {Remove-CDDrive, Remove-Cluster, Remove-CustomFie…
   9:    15 Send                      {Send-Email, Send-FTP, Send-IM, Send-Mail, Send-M…
  10:    14 Write                     {Write-BZip2, Write-Clipboard, Write-Debug, Write…
  11:    13 Invoke                    {Invoke-Command, Invoke-Expression, Invoke-Histor…
  12:    11 Out                       {Out-Chart, Out-Clipboard, Out-Default, Out-File,…
  13:    10 Add                       {Add-Contact, Add-Content, Add-History, Add-Membe…
  14:    10 Move                      {Move-Cluster, Move-Datacenter, Move-Folder, Move…

I just realized the above is the CLI equivalent of looking at a screenshot of someone’s Windows desktop and wondering what all those tray icons do.  :)

What snapins do you think I have installed?  What about you guys?




PowerScripting Podcast - Episode 24 - Admin Script Editor

3 05 2008

A Podcast about Windows PowerShell.

Listen:

In This Episode

  • Today we’ll be speaking to Steven Behrns from iTripoli, the developers who brought you Admin Script Editor. Also on tap: news, resources, and a bunch of PowerShell tips for you. In addition, we’ve got a product giveaway, the first of many! But you have to listen to find out how to enter. :)

News

The News today is sponsored by SDM Software.

Before we go into the spiel, I’d like to mention that we’ve gotten some great feedback from Quest already, so thanks to everyone who has done a clickthrough and filled out the form. You do keep doing that, and we keep the advertisers happy, and that allows US to do more for you. You will start to see the results of that in this very show!

“SDM Software provides innovative solutions that combine PowerShell and Group Policy to help reduce the complexity of managing your Windows systems. Their unique GPExpert Scripting Toolkit for PowerShell, provides the means to automate the management of your Group Policy Objects.
To get more information about these products and download trial copies,
visit sdmsoftware.com/powerscripting.php.”

  • We want to highlight a ton of IMPORTANT posts which Jeffrey Snover has made over the past few weeks:
    • How Could You Top CTP1?
      • This post has the background for why and how some upcoming changes will be made.
    • Changes in upcoming CTP
      • This post has an extract from the release notes for CTP2. Very important to read if you want to keep up with the new version. There’s also some good discussion in the comments attached to the article.
    • Get-Random
      • I love this quote: I saw THIS posting over on Mark Minasi’s forums that caught my eye. It gives you a random help file under the motto of: “A powershell help file a day, keeps Don Jones away”
      • The article goes on to talk about a new cmdlet by the name Get-Random which will get you a random number, or–grab a random item from a collection.
  • iTripoli just released version 3.5 of their Admin Script Editor. (Should be out by the time you read this.) It now includes a debugger and has a ton of PowerShell templates.
  • VMware just announced that Beta 2 of VMware Server 2 (the free version of their virtualization software) is manageable by their PowerShell Toolkit! This is awesome news for smaller shops which have not shelled out for their higher-end Virtual Infrastructure products.

Interview

[sponsor] Our interview today is brought to you by Quest Software.
Quest LOVES PowerShell. Go to www.quest.com / PowerShell and download their free graphical user interface, script editor and Active Directory cmdlets. While you’re there, join their online community where you can share ideas and download free PowerPacks to extend PowerGUI. Visit www.quest.com / powershell today!

We interview Steven Behrns from iTripoli in today’s show. Be sure to listen! Here are some of the questions we asked him.

  1. Who is Steven? What do you do at iTripoli, and what is your background?
    1. co-founder
    2. company started in 2001 w/Bob Kelly. Kixscript editor
  2. What are your favorite features?
    1. Comprehensive code wizards to generate ps script code for ADSI, WMI, XML, database connections, etc.
    2. Script packager, turns your scripts into an executable.
    3. Script Form Designer
  3. When did iTripoli get into PowerShell? Was it a hard sell internally or was this an obvious way forward for ASE?
    1. Thought about this in 2006 during a code overhaul discussion.
    2. First supported powershell in spring of 2007 with the release of 3.0.
  4. What are the primary design goals for ASE? How has it done in the marketplace and changed over time?
    1. Everything related to making scripting tasks easier.
    2. They want ASE to appear invisible and intuitive to the scripters.
  5. How long was the dev cycle (for PowerShell support)? What were your greatest challenges?
  6. Where do you see PowerShell in two years? How will ASE evolve to match it?
  7. So I heard you have something to show us?
    1. They wrote a podcast / MP3 player entirely in PowerShell as an example of how much you can do.
    2. The graphics in the GUI are embedded WITHIN the script file using base-64 encoding.

Thanks a bunch to Steven, we had fun with the interview.

Resources

  • We have two links for you today from John Robbins, author and master debugger. It’s a heartwarming before and after powershell love story. :) He also links to a Compile-Help script which we somehow missed when it was new. This script grabs the help files from all installed cmdlets as well as the about topics, and packages them into a HTML help file for easy reading.
  • Carter at VMware (yes, Hal has a thing about them, sorry) also blogged about a way to have your VMware alert events fire off instant messages using Jabber

One-Liner

  • One liner sent to us by John Cook and a write up on his blog
    • $env:path -replace “;”, “`n”

Give Away

  • A beautiful NFR copy of Windows Vista Ultimate could be yours. Listen to the show for how to enter.



PowerScripting Podcast Episode 23 - IIS7 Special

26 04 2008

A Podcast about Windows PowerShell.

Listen:

In This Episode

  • Today we’ve got an interview with a senior program manager from the IIS team at Microsoft.  We’ve also got news, resources, and a bunch of PowerShell tips for you.

News

The News today is sponsored by SDM Software:
“SDM Software provides innovative solutions that combine PowerShell and Group Policy to help reduce the complexity of managing your Windows systems.  Their unique GPExpert Scripting Toolkit for PowerShell, provides the means to automate the management of your Group Policy Objects. To get more information about these products and download trial copies, visit sdmsoftware.com/powerscripting.php.”

  • Reports are coming in from MVPs right and left that the things they learned about the AD teams forthcoming PowerShell support echoes what were heard in our interview with Jeffery Snover.
  • Thanks to Andrew Westgarth who blogged about some really cool IIS7 news.  There’s a “Tech Preview” now available for a PowerShell provider to manage your IIS server.  Very cool possibilities.  Download and overview are on blogs.iss.net, and on learn.iss.net they have several walkthroughs.
  • Pash - a cross platform open source reimplementation of PowerShell has been released
  • And thanks also to Mark Schill for this one: “Citrix has released some cmdlets for use with their XenServer virtualization product. No where near as powerful as VMWare’s cmdlets, but at least its a start. You can check them out and get more information at this URL.”
  • Windows PowerShell Virtual User Group Meeting #5 happened on April 22
    • Bart DeSmet (Microsoft) gave a cool presentation of script cmdlets
    • Steven Nelson talked briefly about Powershell documentation - PowerShell videos are coming
    • Look for the download at http://MarcoShaw.blogspot.com

Interview

Our interview today is brought to you by Quest Software.
Quest LOVES PowerShell. Go to www.quest.com / PowerShell and download their free graphical user interface, script editor and Active Directory cmdlets. While you’re there, join their online community where you can share ideas and download free PowerPacks to extend PowerGUI.  Visit www.quest.com / powershell today!

Today we speak with Thomas Deml from Microsoft.  He is the Senior Program Manager in the IIS team.  He’s been with MSFT for 17 years!  Old timer. His team “owns” the core engine of IIS and the PS provider is a subset of that.  Below are some notes from the interview.

  • Who are you
  • What’s your background at MS and elsewhere
  • Talk about the IIS7 management cmdlets
    • Get/Set-WebConfiguration
    • Start-WebItem
    • Remove-WebConfigurationProperty
    • Ability to use XPath filters
  • Talk about the IIS7 PSprovider
    • Provider timeline - 2nd beta in June, final in October
    • Features
      • ability to configure IIS and ASP.net, sites, vdirs, apps, all that
      • ability to delegate
      • root of namespace: sites, app pools
  • What does the future hold (that you can discuss)
    • We talk about Server Core

Resources

Tips

  • This came up on #PowerShell (on freenode.net): How can I remove an item from a collection? 
    For example “$servers = get-QADComputer srv*”.

    • Option 1 - Set the item to $null.  This does not actually remove the item, but for most purposes it serves well.
      • $servers[3] = $null
    • Option 2 - Create a new collection which is a subset of the first.  Drawback here is double the memory as the collection is copied in place.
      • $servers = $servers -ne “itemthatyouwantremoved”
    • Option 3 - Use system.collection.arraylist instead of a generic array.  More steps, but the item or items are removed, and it much more efficient than option 2.  The Scripting Guys explain it well in one of their PowerShell tips of the week.
      • $servers = new-object system.collection.arraylist; $servers.Remove(”item”)
  • PowerShell Power User Tips: Current Directory - The core of this tip is very simple: Windows tracks your application’s “current directory” … and you can get and set this location using static methods of the System.IO.Directory class: SetCurrentDirectory and GetCurrentDirectory.  (Thanks Jaykul of Huddledmasses.org.)
  • Newsgroup posts
    • Excel Row Format” - In this thread, Oisin explains how to teach yourself how to automate Excel by examining vbscript created by the macro recorder.
  • This snippet is from Chris in Charleston, SC.  He sent a long email with feedback (which you all should do) with several suggestions.  Thanks, Chris!  This tip is that it’s quite easy to integrate the old with the new in PowerShell.  He’d also found that grep.exe in some cases is much faster than select-string, so it was a good example for his point.  Jonathan’s test had Grep for Windows 2:30 and Select-String 11:08 against the same 6.7 GB log file.
    • $cmd = “grep.exe `”$username`” $logfile”
      Invoke-Expression $cmd | Set-Content F:\4report\$username.txt
  • Don Jones post “Include in PowerShell” dot source a PS1 file at the beginning of your script - http://blog.sapien.com/index.php/2008/04/08/include-in-powershell/



Where did the time go?

18 04 2008

First, I go on vacation (this is Hal typing). Then, Jonathan has a big project at work which takes up our next available studio slot. Then, my weekend just totally filled up end to end. I’m afraid we still haven’t gotten Episode 23 out yet, folks! But fear not, this will not become a habit. We were really good about the two-week rotation, we’ll get back to it very soon.

In the meantime, let me tell you what we’re working on in upcoming episodes:

  • An Active Directory special which will have not one but TWO MVPs (plus Jonathan who is a pro himself) around to answer your questions.
  • A VMware special with a manager for part of their powershell efforts and possibly one of the devs on that team.
  • IIS7 has a new PS Provider which will give you a filesystem-style interface to your site’s data and metadata (so I understand so far). We’re trying to line up the MS Program Manager for that tool, he’s volunteered so we just need to make the schedule work out.
  • We’ve got the WinRM special. I think we’ll be able to get someone from the Server 2008 team to show up for that.

And there are a ton of other stuff out there. For example, I just realized we should have a Group Policy special, I know who to call upon for that. GPO Guy to the rescue! Oh, and MOM/SC, I know a local MVP for that who I’ll draft for the cause.

What would help us out more than anything from you guys reading is to leave feedback on the blog or send email in to powerscripting@gmail.com and let us know what strikes your fancy the most. Or if you have specific questions about the above technologies relating to how you can use them with PowerShell, send them on please.

We’ll get that next episode out RSN!




Vacation delay

14 04 2008

Hi all. Just wanted to let you know that I was out of town on vacation last week, so Jonathan and I were unable to record the show at our usual time. We’re getting together to record again this Thursday with an estimated air date of April 20th.

To make it up for you, we’ll try to do several blog posts this week with pointers to cool PowerShell stuff. I’ll start it off with this one from a very persistent sysadmin Ken who blogged his techniques for displaying some sweet PowerGadgets-powered gauges to monitor the CPU and memory utilization on VMware ESX servers. I say persistent because the solution did require a lot of work to get just right, and he goes into detail about those challenges so it makes a great tutorial for those new to PowerGadgets and the VMware VI Toolkit.




PowerScripting Podcast - Episode 22 "The One About Brandon"

29 03 2008

A Podcast about Windows PowerShell.

Listen:

In This Episode

Today we’ll bring you the second half of our interview with Jeffrey Snover. We think this part is even better than the first half. We’ve also got some news, resources, and a bunch of PowerShell tips for you.

News

The News today is sponsored by SDM Software:

“SDM Software provides innovative solutions that combine PowerShell and Group Policy to help reduce the complexity of managing your Windows systems. Their unique GPExpert Scripting Toolkit for PowerShell, provides the means to automate the management of your Group Policy Objects. To get more information about these products and download trial copies, visit sdmsoftware.com/powerscripting.php.”

  • NEW: NetCmdlets V2.0 - BETA. NetCmdlets V2 is packed full of exciting new features including PowerShell Server (formerly PowerShell Remoting), Parameter Sets, Object Pipelining, and new Cmdlets for SSH Enabled Remoting and Amazon Web Services (S3) Integration. (Thanks to Jeffrey and Marco.)
  • /\/\o\/\/ has updated his PowerShell WMI Explorer for the CTP so you can use alternate credentials

Interview with Jeffrey Snover

Our interview today is brought to you by Quest Software.

Quest LOVES PowerShell. Go to www.quest.com / PowerShell and download their free graphical user interface, script editor and Active Directory commands. While you’re there, join their online community where you can share ideas and get free useful commands. Visit www.quest.com / powershell today!

Be sure to listen to the show for the interview. You can read a list of the questions here.

Resources

Tips

The Tips are brought to you today by ShellTools.

Did you know that PowerShell Plus is a great XML editor? In addition to .PS1 files, you can also work with .PS1XML help files and .PSC PowerShell Console files. Other new features include a really cool console preview pane in the editor which makes edit/test/correct workflow very easy. You can download it today at shelltools.com.

  • Brandon Shell from the BSonPosh blog wrote a cool script which times the replication of objects in an Active Directory. Here are the features:
    • Finds all Domain Controllers in the Domain (using .NET)
    • Creates a contact object in a specified OU (Default is users container for the Domain)
    • Gets the start Time
    • Loops and Checks each DC for the object.
    • Once all DCs have the object it gets End Time
  • Newsgroup posts:
    • Hal explains how to explore WMI in the command-line:
  • Bart De Smet wrote a cool introduction to Script Cmdlets in PowerShell v2 CTP. It will be incredibly easy to write more robust scripts that have features such as mandatory parameters and “it just works” pipeline support. He also talks about -confirm and -whatif support. Very neat stuff.



Get-Directory Function

24 03 2008

In the olden days (i.e. when I used CMD.EXE), I often did “dir *.” to quickly get a list of the directories in the current path. PowerShell doesn’t work this way (which is good because it would be unexpected), so I had to make a replacement.

function Get-Directory { ls $Args | ? { $_.PSIsContainer } }

The alias which makes most sense to me for this function is “lsd”. What, that acronym is already in use? :)




PowerScripting Podcast Episode 21, "One-half of Jeffrey Snover"

17 03 2008

A Podcast about Windows PowerShell.

Listen:

In This Episode

This week, our Intrepid Heroes talk about News in the PowerShell world, bring you fresh Resources from the wild Internet, and share their experiences in the Tips section, with you, the Listener. Oh–and we also interview JEFFREY SNOVER! In case you don’t know who he is, he’s basically like the Thomas Edison of scripting.

Interview with Jeffrey Snover

And now a word from our sponsor:

Our interview today is brought to you by Quest Software. Quest LOVES PowerShell. Go to www.quest.com / PowerShell and download their free graphical user interface, script editor and Active Directory commands. While you’re there, join their online community where you can share ideas and get free useful commands.  Visit www.quest.com / powershell today!

Be sure to listen to the show for the interview. You can read a list of the questions here. The interview ran really long (which is awesome), but at an hour and a half, it was too long for our format. So, we decided to split it into two main chunks.

There is stuff in this interview you have not heard anywhere else before, so check it out. Maybe some people don’t like it when Jeffrey talks so long, but we sure did.

News

Resources

Stay tuned, kids! We’ll be back after a brief message from our sponsors.

The resource section today is sponsored by SDM Software:
“SDM Software provides innovative solutions that combine PowerShell
and Group Policy to help reduce the complexity of managing your
Windows systems. Their unique GPExpert Scripting Toolkit for
PowerShell, provides the means to automate the management of your
Group Policy Objects. To get more information about these products and download trial copies, visit
sdmsoftware.com/powerscripting.php.”

Tips

    The Tips are brought to you today by our friends at ShellTools.

    Did you know that PowerShell Plus is a great XML editor? In addition to .PS1 files, you can also work with .PS1XML help files and .PSC PowerShell Console files. Other new features include a really cool console preview pane in the editor which makes edit/test/correct workflow very easy. You can download it today at shelltools.com.

  • Some notable built-in aliases you might not have noticed:
    • diff -> compare-object
    • group -> group-object
    • iex -> invoke-expression
    • ii -> invoke-item
    • sleep -> start-sleep
    • sort -> sort-object
    • kill -> stop-process
  • We discuss a forum post which asks, “How can I verify a URL redirection?” We answer the question using the System.Net.HttpWebRequest .NET object.(from powershellcommunity.org)
  • Assign multiple variables in one expression (Get-PowerShell blog). Andy gets all the air time today.

One-liner

This one-liner lets you quickly make a GUID (globally unique identifier):

write ([string][guid]::NewGuid())

Also don’t forget to check our blog from time-to-time, we like to post little tidbits in-between shows like one-liners so don’t miss out! Hal just posted a PowerShell kitchen timer one-liner today.

Thanks for listening! You can send feedback to powerscripting@gmail.com.




Episode 21 coming soon.

17 03 2008

I just wanted to let you know that the new podcast should be posted by Tuesday morning. We had a great interview with Jeffery Snover that you don’t want to miss!




One-Liner: Countdown Timer in PowerShell

16 03 2008

Here’s a quick one for ya. Perfect kitchen timer. Who doesn’t have a laptop with PowerShell on it in their kitchen? :)

start-sleep (60*9); write-host ("`a"*4)

Start-Sleep works in seconds, so you see where I’ve done some quick
math to get nine minutes. Not sure if the ()’s were required, but they
don’t hurt. I didn’t know the precedence of parameter parsing versus
multiplication off the top of my head. Next is Write-Host with some
more multiplication. This one uses “`a” which is the special character
which emits a beep (old schoolers know this as the ASCII code for
BELL). If you multiply a string by a number in this way (and in this
order, actually), then posh concatenates it the number of times you
specify. Due to the magical parsing that PowerShell does, if you were
to try this the other way around, with the 4 first, you would get an
error when it tries to convert “`a” to an INT.

Happy Powershelling!