When in doubt, ask the community

In case you hadn’t noticed already, there are many people who are ready, eager and waiting to help you with your next PowerShell problem.  The list of PowerShell enthusiasts is long and growing steadily, and they’re responsiveness to questions is incredible.  So responsive in fact that it seems like there is a competition to see who can answer questions first!

Leverage that community!

If you have questions, post them somewhere.  If you have scripts that you can’t quite work out, share them and get the community to help.  If you think you can work it out but just want a few pointers, search the community and find if the answers you seek have already been posted somewhere.  There’s really no reason to wait.  If you’re stumped, ask for help and you’ll get it.

Here’s an updated (thanks to Hal for pointing out some important ones that I missed) list of just a few places you can go if you have questions:

  1. PowerShell Newsgroup – a very active newsgroup for discussions about anything related to PowerShell
  2. PowerGUI Community – the place to go to share PowerGUI PowerPacks or to ask questions about PowerGUI and Quest AD cmdlets
  3. PowerShell Community – a non-profit PowerShell Community site with forums for anything related to PowerShell, a script repository, and much more
  4. PowerShell Blog Search – a custom Google search of many PowerShell blogs; created and maintained by Brandon Shell (PowerShell MVP)
  5. The PowerScripting Podcast – a semi-weekly podcast about everything PowerShell; Jonathan Walz and Hal Rottenburg are the hosts, and this is a great source of current PowerShell information, interviews, tips and tricks, etc.
  6. PowerShell IRC channel (#PowerShell on irc.freenode.net) – an IRC chat room with many PowerShell savvy people hanging out, discussing PowerShell, ready to answer your questions right then and there.

If you’re looking for help on PowerShell, please use the community.  You’ll be thankful you did!

Kirk out.

Technorati Tags: , , , , ,

Tracking time while presenting PowerShell

I don’t wear a watch.  Maybe I should, but I feel like there are too many clocks in the world already and I don’t want to add to that by putting one on my wrist.  This works just fine for me for the most part.

But last week I was busy having fun giving an introductory presentation about PowerShell to the Ottawa Windows Server User Group and since I can talk about PowerShell for hours without getting tired of it I needed to keep a closer eye on the time.  And with my PowerShell slide deck often full screen on my laptop, I couldn’t rely on the small little clock in my system tray to do the job.  What to do, what to do…

Well since I was demoing PowerShell and some of the many products available that support PowerShell, I came up with a solution that would both keep my eyes on the time and at the same time give me a nice segway within my presentation into a short discussion about PowerGadgets and what they can do.  Here’s a screenshot to show you what I mean:

Presenting PowerShell with a PowerGadgets Clock

See that little digital clock in the corner?  That’s a PowerGadget.  Here’s a close-up of it (taken at a later time):

PowerGadgets Clock Close-Up

It’s configured to always be on top of my desktop, and it is running a short PowerShell script every minute to get the current time in short format.  This doesn’t even begin to scratch the surface of what you can do with PowerGadgets, but it was definitely a nice opportunity to show just one of the many great things being done with PowerShell in the market today.  And it took all of 2 minutes to make it too!

Judging from many attendees at the presentation taking notes about PowerGadgets when I showed them this as well as how easy it can be to use, I think it made a good impression on them as well.  If you are curious about PowerShell and would like to see what some of your data presentation options are, take a look at what PowerGadgets has to offer.

Oh, and since PowerGadgets comes with cmdlets that can be used to create them, you can launch them from within PowerGUI too.  Two rich PowerShell tools that work great together already!  And we haven’t even gotten to the release of version 2 of PowerShell yet!  This certainly is a fun space to be in!

Kirk out.

Technorati Tags: , , , ,

Improving the PowerGUI out-of-the-box experience

One of the things that I’ve been tasked with as part of my PowerGUI duties is to improve the PowerGUI out-of-the-box experience by adding new nodes, links and actions to the default PowerGUI tree so that you get a richer set of functionality right off the bat.  In order to do this right the first time, I’d like to solicit input from any PowerGUI users out there who have either added functionality to the tree that they’d like to share or who would like to put some requests on the table for functionality that they’d like to see in the default PowerGUI tree.

For starters I’d like to stick with the existing root nodes we have in the tree and get your feedback on things you would like to see to enhance that offering with additional functionality.  If you would like to contribute, please either leave a comment on this blog, post a suggestion to the PowerGUI community forums, or email me directly.  My email address ID is simply the title of this blog and I’m using Google’s free email service.  Hopefully that’s not too cryptic for you to piece it together.  The hoops we have to jump through to avoid being discovered by web crawling spam bots… )

Kirk out.

Technorati Tags: , , ,

PowerShell Deep Dive: Discovering dynamic parameters

Not too long ago when I posted an Invoke-Cmdlet function that could be used to extend PowerShell cmdlets, I indicated that I would soon post an example of how I use it to extend a cmdlet’s core functionality.  In this post I will show you that example, where I will extend the Get-Help cmdlet such that it is able to include provider-specific syntaxes for core cmdlets and documentation for any dynamic parameter that supports a given cmdlet regardless of what provider they come from.  Before I show you that example though, I should provide a little background information on core cmdlets and dynamic parameters and why this extension is important when learning how to use core cmdlets.

Background 

What is a core cmdlet?  A core cmdlet is a PowerShell cmdlet that provides consistent user experience when working with any PowerShell drive, regardless of which PowerShell provider the drive is associated with.  In PowerShell 1.0, the list of core cmdlets include any cmdlet with one of the following nouns: ChildItem, Content, Item, ItemProperty, Location, Path, PSDrive or PSProvider.  To see the entire list of core cmdlets, simply execute ‘Get-Help about_core_commands’ in PowerShell.

What is a dynamic parameter?  A dynamic parameter is a provider-specific parameter that is conditionally available on one or more core cmdlets that come with PowerShell.  Dynamic parameters are used to extend the functionality in core cmdlets so that they can use some functionality that is only available when working with certain providers.

How can I find out which dynamic parameters are available for a core cmdlet and where can I read documentation about them?  If you’re trying to learn more about a core cmdlet in PowerShell 1.0, and if you want to find out information about the dynamic parameters that are available for that cmdlet, you have the following options:

  1. Execute ‘Get-Help CmdletName -Full’ in PowerShell and hope that your dynamic parameter was included in the default documentation for the cmdlet.  With very few exceptions, if you do this you’ll most likely find the documentation you’re looking for isn’t available.  For example, the CodeSigningCert dynamic parameter is included in the parameter documentation for Get-ChildItem, but it is not included in syntax for Get-ChildItem nor is it included in the parameter documentation or syntax for Get-Item where it also applies.  Most dynamic parameters that are part of the providers included in PowerShell 1.0 are not included in the default cmdlet documentation, and no dynamic parameters that are available through third-party providers are included in the default cmdlet documentation (obviously, because they didn’t exist at the time that the PowerShell documentation was written).
  2. Use the Syntax parameter and optionally the ArgumentList parameter of Get-Command to view the syntax for the core cmdlet you are curious about when working with a specific provider.  If you only use the Syntax parameter, then the syntax that is returned will be for the provider associated with the current working directory.  If you pass in a path in the ArgumentList parameter as well, then the syntax that is returned will be for the provider associated with that path.  This works well when you are doing ad-hoc scripting using the drive that hosts your current working directory and you just want the syntax without other help details, but if you are working in an IDE and writing scripts without the concept of a current working directory or if you want more documentation about the dynamic parameters you’ll have to go elsewhere for information.
  3. Execute ‘Get-Help -Category Provider -Name ProviderName‘ in PowerShell and then look in the section titled “Dynamic Parameters” to see what dynamic parameters are added and which core cmdlets they are added to.  This is the most useful out-of-the-box way to find help on dynamic parameters, but the help information is in a slightly different format than other parameter help and to truly get the big picture for the cmdlet and how it works with different providers you need to refer to the provider help AND the cmdlet help just to get parameter information.  Add to that the fact that you don’t get to see the updated syntax unless you use Get-Command with the Syntax parameter and it all adds up to more work than you should have to do just to learn everything about how a cmdlet works.

Based on these options, you can see that it is possible to retrieve all of the help documentation for a core cmdlet when working with a particular provider but it requires multiple calls and the documentation isn’t nicely compiled together into a comprehensive document.  I wasn’t satisfied with this because I thought I should be able to see all of the help information for a given cmdlet inside the documentation for that cmdlet.  In fact, I expected that it functioned this way from the start and used core cmdlets during many months of working with PowerShell oblivious to the fact some of them had dynamic parameters.  I simply didn’t know the dynamic parameters existed until I came across a dynamic parameter in PowerShell when using tab completion for a core cmdlet that had dynamic parameters for my current working directory at the time.  Cmdlet parameters shouldn’t be found just by chance like that.

There are other problems with the out-of-the-box implementation of dynamic parameters as well.  One of my favorite tricks for the Get-Help cmdlet these days is to use it to discover cmdlets with similar parameters.  For example, to see all cmdlets containing parameters with ‘path’ as a substring of one or more parameter names, you can simply execute ‘Get-Help * -Parameter *path*’. But this only works for parameters that are in the parameter list in the documentation for a cmdlet.  If a dynamic parameter exists that isn’t included in that parameter list in the cmdlet documentation, that parameter won’t be found.  Because of how this works behind the scenes, if the documentation for cmdlets did include all parameters, including dynamic ones, you could use this same trick to find all cmdlets that use a dynamic parameter.  Unfortunately, that won’t work though because as I mentioned earlier, the documentation for the vast majority of core cmdlets does not include dynamic parameters.

There are other examples to further illustrate how hidden dynamic parameters are, including the following:

  • They don’t show up when using tab completion or PowerTab unless the provider associated with the current working directory has the dynamic parameters you are looking for (and therefore if you try to use tab completion or PowerTab at the end of this line, you will never see the Type parameter: ‘Set-Item -LiteralPath hkcu:\temp -‘.
  • They don’t show up when using PowerShell Plus for the same reason as above (and since PowerShell Plus uses PowerTab internally this is completely understandable).
  • They don’t show up when using Intellisense in PowerGUI.

Not being satisfied with this, I started investigating what I could do to improve on the user experience by making dynamic parameters much more discoverable in the documentation.  Then it dawned on me that I should be able to extend the Get-Help cmdlet so that the documentation it returns will include all dynamic parameters, in both the cmdlet syntax and the cmdlet parameter lists.

Introducing the CmdletExtensionLibrary.ps1 script

The trick to extending existing cmdlets is to wrap them in functions of the same name.  Within those functions you can do whatever extra work you want done and then call the original cmdlet using the Invoke-Cmdlet function I referred to earlier.  This works because function names take precedence over cmdlet names in command name resolution.

Using that information as well as the knowledge I gained when researching dynamic parameters, I have created a CmdletExtensionLibrary.ps1 PowerShell script file that includes the following functions:

  1. Get-PSResourceString
    The Get-PSResourceString function returns a resource string that is looked up in the System.Management.Automation namespace. It is used to load error messages and localized strings used in PowerShell cmdlet documentation so that the Get-Help extension properly displays the added help documentation in the current culture.
  2. Invoke-Cmdlet
    This function is the same as the one I published on my blog earlier.  It is used to invoke a cmdlet by using its fully qualified name.
  3. Get-DynamicParameterMap
    The Get-DynamicParameterMap function extracts the dynamic parameter help information from the PSProvider help documentation and builds a map of cmdlet names to dynamic parameters.
  4. Add-PSSnapin
    The Add-PSSnapin function is a simple wrapper around the Add-PSSnapin cmdlet.  Once the snapin is added, it refreshes the dynamic parameter map using the Get-DynamicParameterMap function.  This is necessary to ensure that dynamic parameter information is always up to date with the list of PSSnapins that have been added in the PowerShell session.
  5. Remove-PSSnapin
    The Remove-PSSnapin function is a simple wrapper around the Remove-PSSnapin cmdlet.  Once the snapin is removed, it refreshes the dynamic parameter map using the Get-DynamicParameterMap function.  This is necessary to ensure that dynamic parameter information is always up to date with the list of PSSnapins that have been added in the PowerShell session.
  6. Get-Help
    The Get-Help function integrates the dynamic parameter documentation directly into the help documentation for any core cmdlet where they apply.  This includes the cmdlet syntax as well as the cmdlet parameter help information.  Once integrated, the dynamic parameter documentation will be displayed in the same language as the rest of the documention.

 You can find the latest revision of the CmdletExtensionLibrary.ps1 file in the Script Vault on the PowerShell Community site.  Alternatively, if you want to access it directly you can get it here.

All of the functions in the CmdletExtensionLibrary.ps1 file are fully documented in comments that precede the function definitions.  In order to add these functions to your PowerShell session, simply dot source the file (e.g. ‘. C:\MyPSScripts\CmdletExtensionLibrary.ps1’).  If you want these extensions always loaded, place the dot source command you just ran into the appropriate profile or copy the functions you want directly into your profile (but be careful when doing this since many of the functions call other functions in the same file so if you leave some out others may not work).

Once the functions are available in your PowerShell session, you should start noticing the full cmdlet documentation for core cmdlets when you execute Get-Help.  You can see this in PowerShell by executing any of the following commands:

  • Get-Help * -Parameter Wait
  • Add-PSSnapin pscx; Get-Help * -Parameter Raw
  • Help Set-Item -Full
  • Get-Help Set-Item -Full | more

When running these commands you will notice how dynamic parameters are now included in the documentation (and are therefore discoverable using the -Parameter parameter for Get-Help).  For the first two commands you will get information that was not previously available via Get-Help.  For the last two commands you will see that the cmdlet documentation includes all available syntaxes, including provider-specific syntaxes, as well as parameter help for every dynamic parameter that is available.  Also note that both the Help function and the Get-Help cmdlet automatically support the Get-Help cmdlet extension function, providing seamless integration into your PowerShell environment.  Is that cool or what?  It’s amazing how much you can do to customize PowerShell to your liking.  Hats off to the PowerShell team for making such a wonderful and flexible scripting environment!

I should point out that adding this set of functions to your PowerShell session does not make the dynamic parameters show up in tab completion or Intellisense in any of the products mentioned above.  I believe this could be done by creating a Get-Command extension that returns all available syntaxes for a core cmdlet, including provider-specific syntaxes.  I will have to test that theory out later and possibly update this library to support that as well.

Also, despite everything that I did figure out with respect to dynamic parameters I still have one big unanswered question.  If the purpose of dynamic parameters is to allow generic core cmdlets to access some provider-specific functionality then why are there dynamic parameters in the Exchange cmdlets?  For example, run the script below this paragraph before and after you add the Exchange cmdlets to your environment.  Before you add the Exchange snapin, the script will return all core cmdlets that have dynamic parameters (based on the provider associated with the current working directory).  After you add the Exchange snapin, the script will return the same core cmdlets as before plus many Exchange cmdlets.  It doesn’t make sense to me that parameters would be marked as dynamic in Exchange since there isn’t a provider for Exchange and therefore the core cmdlets do not work against Exchange.  Here is the script I was referring to:

foreach ($cmdlet in Get-Command -CommandType Cmdlet) {
   
$cmdlet.ParameterSets | ForEach-Object {
       
$_.Parameters | Where-Object { $_.IsDynamic } | ForEach-Object {
           
$cmdlet.Name | Write-Output
           
continue
        }
   
}
}

That about wraps it up for this post.  I have tested the CmdletExtensionLibrary.ps1 functions pretty extensively on Windows XP SP2 using PowerShell in English and also in French with the PowerShell MUI pack.  That doesn’t mean there aren’t any issues in these functions, though, so if you find any please report them back to me and I’ll try to resolve them for you.

Kirk out.

Technorati Tags: , , , , , , , ,

Change is a very good thing

For over half a year I’ve spent every free moment I could muster outside of work using PowerShell or a PowerShell related tool.  I made the decision a while back to do this with a few goals in mind, and today I finally achieved one of those goals.  Today marks my first day as a member of the PowerGUI team at Quest Software!  I couldn’t be happier about it!

Kirk out.

Technorati Tags: , , ,

Something wicked this way comes…

Troubleshooting PowerShell scripts is about to get easier.

I’ve had the privilege of beta testing early builds of PowerGUI 1.0.12 for the past couple of weeks, and it’s just fantastic!  This release is not generally available yet, but it will be very soon.  To wet your appetite, here’s a screenshot of the PowerGUI Script Editor that is included in the PowerGUI 1.0.12 release.

PowerGUI 1.0.12 Script Editor

Keep your eyes on the PowerGUI Community Site and Dmitry’s blog for news about the official release of PowerGUI 1.0.12 over the next week!

Kirk out.

Technorati Tags: , , , , , ,

Full Circle: Life in the FastLane

In early 1997 I started my professional career with a small start-up company called FastLane Technologies Incorporated.  I believe I was employee number 12 or 13 at the time; I can’t recall exactly which.  It was my first job out of university and my task was to add commands to a scripting language called FINAL (FastLane Integrated Network Application Language).  This product was quite amazing in its time.  It gave administrators a scripting environment with a pretty large quantity of commands so that they could administer their Windows (at the time NT, and then later 2000) environments more easily through automation (sound familiar?).  It was quite a successful product, impressing people by how few lines of script they would have to write to get their job done.

As time went on FastLane expanded their product offering and began developing GUI products that were built on top of the FINAL scripting language (again, this sure seems familiar).  These “point solutions” were designed to solve administration pains through a GUI that allowed them to point-and-click their way to administrative bliss.  Eventually the FINAL scripting language evolved such that you could take advantage of its functionality by being able to call its commands from other languages too.  In this form it was called DM/Developer.  Shortly after that, in August of 1999 I left FastLane to persue opportunities with a few other start-ups until I returned to my professional roots in January of 2004 when I accepted a job at Quest Software (I say my professional roots because Quest Software bought FastLane on June 29, 2000; in fact, many of the old FastLaners I used to work with are still with Quest Software today and others that have left in the past have returned as well).

Now, more than 10 years since I started my career working with a scripting language that was designed to allow Windows administrators to automate many Windows administration tasks, here I am spending every free minute I can working with a scripting language that was designed to allow Windows administrators to automate many Windows administration tasks.  And it just so happens that my employer has a product called PowerGUI, a product build on top of the PowerShell scripting language to help solve administration scripting pains through a GUI.

Is that déjà vu, or what?

Life in the FastLane truly has come full circle for me, and I couldn’t be happier about it!

Kirk out.

Technorati Tags: , , ,

It’s a great time to be a Poshoholic!

What a fun time to be working with PowerShell!

Just this weekend I got my hands on the beta of PowerShell Plus and I started looking at the new PowerShell Community site that soft-launches tomorrow.  Last Monday PowerGUI 1.0.11 was released with the fantastic PowerGUI Script Editor.  On Friday version 1.0.5 of the Quest AD Cmdlets was released.  The Virtual PowerShell User Group hosted their inaugural meeting earlier this month (if you missed this you can get the recorded video here).  Local user groups are starting to talk about PowerShell and spread the good word.  PowerShell Analyzer 1.0 is about a week away.  Next month Jeffrey Snover will be presenting new features in PowerShell 2.0 at TechEd IT Forum 2007 in Barcelona (I hope there will be a webcast for that session!).  VMWare is providing a technology preview of their ESX server snapin to testers soon.  The library of PowerShell books that are available keeps growing.  More and more Microsoft and third-party products are releasing with their own PowerShell snapins.  Add to that PowerGadgets, PowerShell Community Extensions, the PowerScripting Podcast, several active community sites, a busy newsgroup, lots of webcasts, many other PowerShell projects on CodePlex and likely a bunch of things I’m not able to think of right now and you can’t help but feel that it really is a great time to be a Poshoholic!  Are you on the train yet?

Kirk out.

Technorati Tags: , , , ,

PowerGUI 1.0.11 with the PowerGUI Script Editor is now available

Following up the teaser post that I published this past weekend, I’m happy to tell you that PowerGUI 1.0.11 was officially released yesterday.  This is a truly great product, it’s free, and it is a must have for any serious user of PowerShell.  If you’re still not convinced that you should be using this product, take a look at Dmitry Sotnikov’s post about “Notepad for PowerShell”.  It includes a screenshot of the fantastic PowerGUI Script Editor application that was included as part of this release plus other details.

Enjoy!

Kirk out.

Technorati Tags: , , , ,

PowerGUI 1.0.11 release is just around the corner!

According to Dmitry Sotnikov‘s most recent blog post, the next release of PowerGUI (version 1.0.11) is slated for next week.  It may even be available by the time you read this post!  I have had the great pleasure of beta testing PowerGUI 1.0.11 for the past week or so, and this is another fantastic release of this truly great product.

As with previous upgrades to PowerGUI it only takes a few minutes with the new version to see that the PowerGUI team has been very busy enhancing this product.  I hadn’t even finished the installation of the new version when I became totally distracted after noticing one of the enhancements in this version, the PowerGUI Script Editor.  This feature is great news for the PowerShell Community!  Finally a PowerShell script editor with great features that facilitate writing scripts even when you don’t know the syntax by heart, and a free one to boot!  Working with PowerShell just got much, much easier.

Add to that the performance improvements to the startup time for PowerGUI and all of the bug fixes, and you’ve got yourself another great release from the PowerGUI product team!  For a full list of enhancements and bug fixes, check the PowerGUI Feature Map page.

For those of you who haven’t tried PowerGUI yet, this would be a great release to start with!  It’s free and it adds a ton of value to working with PowerShell so there’s really no reason not to try it if you’re even remotely interested in PowerShell and wondering what all the fuss is about.  Plus there is a very active PowerGUI community where you can post questions, notify the developers about possible defects, watch webcasts to see how it works, and raise enhancement requests.  The PowerGUI team actively monitors and participates in the community, so if you need help with anything or want to start a discussion about using PowerShell with PowerGUI, about PowerGUI itself or about the Quest AD cmdlets, this is the right place to go!  I’m a regular on the community forums and will likely try to respond to your questions if someone from the PowerGUI or Quest AD cmdlets teams doesn’t get back to you first.

Kudos to the PowerGUI team for the fantastic products they’re producing!  I can’t wait to see what they’ll do next!

Kirk out.

Technorati Tags: , , , , , ,