PowerShell Not Your Father’s Command Line Part 29 of 31: Demystifying MSDN and PowerShell static syntax

Originally, this post was going to be about GUIs, but after waking up this morning and seeing a comment on Part 28, I figured that I’d address that comment in this post.

Paul Bendall writes:

But how does an ITPro without a developer background start to use MSDN and understand terminology such as static, override, []::Something?

Let’s demystify some of the things at MSDN so that maybe you guys without a developer background can make sense of it.

Terminology Elevator – Ground Floor – Objects

Objects are… um… objects in programming terminology. An object could be words, numbers, a computer, anything really. In Appendix B in our book, I talk about objects at a really high level. Let’s take a similar approach here. Let’s talk about a keyboard.
Rapoo Keyboard from Hong Kong
A keyboard is an object. It has keys – which means that a keyboard could have a collection of objects. Yes, collection can be a technical term referring to a grouping of like or related objects. Now let’s look at a keyboard key… what can you tell me about it?

  • What color is the key?
  • What character or characters are on the keys?
  • How big or small is the key?
  • Is the key enabled?

The answer to these questions would be called properties of the keyboard key. They describe the object in terms of adjectives and capabilities.

  • Press the key.
  • Release the key.

These actions show that the key can respond to events. When an event happens, you can trigger a piece of code to run. In some cases, you may be able to have code run before or after an event happens, depending on the object and event.

Now let’s look at the Caps Lock key. When you press it, the alphabetical keys TYPE CAPITAL LETTERS. This means that not only can this key respond to being pressed, but it also can perform an action called a method. Yes, this also means that the object may call a method while responding to an event.

So an object can have properties, methods, and events.

Terminology Elevator – Level 1 – Class, Static, and Constructor

A class is a container that holds the methods, events, and properties of an object. Using our keyboard key example, a class would be the collection of all of the properties, methods, and events that belong to a keyboard key.

If you find yourself using the New-Object cmdlet and getting the “Constructor not found.” error, that basically is telling you that you are working with a static class.

A constructor is a piece of code that states how to create a new object. This is the piece of code that gets run when an object is created with the New-Object cmdlet.

If the constructor isn’t in the class, then the class is considered static. If something is called static, this means that they are not created, destroyed, or changed – they are simply used.

In PowerShell, the :: operator is used to call out to static methods and properties. The syntax is as follows:

[Namespace.Namespace.ClassName]::Method()

or

[Namespace.Namespace.ClassName]::Property

Yesterday, we looked at the System.Windows.Forms.SystemInformation class and some of its properties. There is also a TechNet article on using static classes and methods in PowerShell.

Terminology Elevator – Level 2 – Assemblies and Namespaces

Assemblies and namespaces are ways to organize code. An assembly is a physical way of organizing code – commonly in a DLL file. A namespace is a logical way of organizing code – grouping code for the same object or collection of objects together.

Looking at the top of the SystemInformation class page on MSDN, you can see that this particular class lives in the System.Windows.Forms.dll assembly. It also belongs to many namespaces – collectively, it belongs to System.Windows.Forms. However, Forms is a namespace that belongs to Windows, which is a namespace that belongs to the System namespace.

Russian Matryoshka dolls - pic taken from http://nelietatravellingadventures.blogspot.com/2010/11/matryoshka-or-nesting-dolls-from-russia.html
One thing you’ll notice with the naming scheme is that the namespaces are stacked like Russian matryoshka dolls – the largest namespace is on the outside, and the smaller namespaces are nested inside, all the way down to the class – which is like that tiny doll at the end.

Terminology Elevator – Observation Deck – Overrides

By default, there are actions that a command can do automatically. However, you may want to customize those actions, which can be done by overriding the action. Basically, if you write code that overrides the default behavior, your code supersedes the default code.

Conclusion

A lot of what you’ll see on MSDN is based on object-oriented programming concepts. Hopefully this post gives you a little idea as to what those terms mean and can help you on your way in using static classes and methods in PowerShell.

PowerShell Not Your Father’s Command Line Part 28 of 31: What is the .NET Framework?

While talking with Hal and Jonathan on the PowerScripting podcast, I was asked the question “What is .NET?” Of course, I mentioned that it’s a framework, but then I choked… the .NET Framework is a huge thing to try to tackle like that, especially when talking with IT pros. Being a developer and working with the .NET framework, I can tell you it’s a collection of libraries that have a whole lot of code that we don’t have to write and can use to make our developing a lot easier. However, I didn’t need to get into it as a developer and needed to suppress the developer speak.

What is the .NET Framework?

When I say that the .NET framework is huge, I’m referring to how much it covers – be it web services, web applications and websites, desktop applications, or yes, even shell scripts. There are libraries – collection of objects and commands – to make it easy to access data, manage configurations, work with accessibility and assistive technologies, address security concerns… just to name a few things that you can do.

What is .NET Framework in terms of PowerShell?

Sean Kearney, a.k.a. The Energized Tech, recently wrote a post titled Understanding .NET from the perspective of an IT Professional. In that post, he talks of assemblies, which developers are quite familiar with. If you have to support developers and they happen to ask you which assemblies are installed on your machine, you could use this:

[appdomain]::CurrentDomain.GetAssemblies() | Select FullName

This command will list all of the assemblies in the current domain. Each assembly listing includes the name, version, culture, and public key token; these fields are key to developers as they need to use those lines when configuring their .NET projects that may live on your server.

The output may look something like this:

PresentationFramework, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35

If you want to work with an assembly that isn’t loaded by default, you could use the Add-Type cmdlet in PowerShell 2.0. For example, let’s say we’re writing a script that gets a computer’s NetBIOS name, the logged-in user’s user name, and the domain. These can easily be accessed by System.Windows.Forms.SystemInformation. To see these details, run the following commands:

Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.SystemInformation]::ComputerName
[System.Windows.Forms.SystemInformation]::UserName
[System.Windows.Forms.SystemInformation]::UserDomainName

And as suggested by Aleksandar Nikolic, here’s a good way to see what static properties and methods belong to the SystemInformation class:

[System.Windows.Forms.SystemInformation] | Get-Member - Static

As you can see, you can use these .NET assemblies from within PowerShell, as PowerShell is built on top of the .NET Framework.

If you have questions about Add-Type, I’d first recommend checking out:

Get-Help Add-Type -examples

Learning More

As I mentioned, the .NET Framework is huge enough to have its own podcast. You can find out more about .NET in the community through the .NET Rocks! podcast, hosted by Carl Franklin and Richard Campbell (one of the co-hosts of the IT pro sister show called RunAs Radio).

Someone else listening to the podcast suggested reading MSDN. My advice – just be familiar with the MSDN Library and how to search it as needed. You’ll find this to be a great resource, especially if you’re going to write your own custom compiled cmdlets, providers, and binary modules.

This was just a high level overview of what the .NET Framework can do. If you want to see more things you can do with the .NET Framework, check out some of the fun projects over at Coding4Fun!

Matt and I want to hear what you’ve thought about the series so far. Leave us comments on our posts or get in touch with us. I can be emailed at sarah at codinggeekette dot com.

Special thanks to Aleksandar Nikolic for catching the typo in this entry. The Add-Type command has been updated.

PowerShell The Community’s Command Line Part 27 of 31: It Takes a Community to Raise a Language

Much like the saying It takes a village to raise a child, it takes a community to raise a programming language. Without passionate people in that community, the word won’t spread and a language can die. Yesterday, I talked about some of the cool community resources and sites. Today, I want to salute those who are working on community projects with PowerShell. These are just a few of the many out there.

StudioShell, by Jim Christopher (@beefarino)

http://studioshell.codeplex.com/
StudioShell is an integrated PowerShell host available inside Visual Studio 2010 and 2008. This tool exposes Visual Studio’s extensibility points and makes it easier to extend your Visual Studio from the command line rather than from compiled binaries. Jim will be giving a presentation on his StudioShell project and using it to extend Visual Studio at CodeStock 2011 down in Knoxville, TN this June.

MongoDB PowerShell Provider, by Jim Christopher

http://mosh.codeplex.com/
If you’re in an environment where you need to manage a Mongo database, then the MongoDB PowerShell Provider may make your life a little easier in managing the database from within PowerShell. This project is nicely documented both on the CodePlex site and from within PowerShell.

PowerShell Script Provider, by Oisin Grehan (@oising)

http://psprovider.codeplex.com/
While developers who can think out a provider’s logic may be more comfortable with writing the provider in C#, this provider allows IT Pros and those comfortable with PowerShell to write their providers in the PowerShell scripting language. Oisin Grehan, PowerShell MVP and PowerShell provider guru, is the guy behind this project. It’s great to see the option of writing providers in PowerShell, as working with the scripting technology directly in its own language makes more sense to many scripters.

Show-UI: The PowerShell WPF Toolkit

Show-UI
For those who have our book, disregard the recommendations on page 397 on the two things to help with WPF apps in PowerShell, as WPK and PowerBoots are merging. Show-UI is the project that they are merging into. Yes, you can use PowerShell to create GUIs. Show-UI is a project that can help make that process even easier in PowerShell. Shoutouts to the coordinators and developers – Jaykul, Doug Finke, and James Brundage.

Others?

Got any other PowerShell projects that you want to share? Leave me a comment!

PowerShell My Father’s Command Line Part 26 of 31: Start Spreading the News…

I’m watching this week’s episode of Glee again while writing this post, and the “I Love New York/New York, New York” mashup really inspired this title. I have to give a shoutout to my dad in the title, as while he isn’t technologically inclined, he taught me the value of networking and establishing relationships. He was a union leader for the city’s emergency response service for many years, and in those years, I watched as he networked with people in his line of work and those who impacted his line of work – councilpeople, mayors, senators, and the like. Watching him, I learned how to network and how to participate in communities.

Up until this point, Matt and I have been talking about scripts and code in PowerShell, but there’s more than just that. If the language didn’t have a community behind it, it would fall flat and not continue on like it has been. So let’s do a shoutout to some of those in the PowerShell community!

2011 Scripting Games

Hey, Scripting Guy!, the Scripting Games, and the Scripting Wife!

Ed Wilson is also known as the Scripting Guy over at Microsoft. He answers languages on various scripting technologies, with PowerShell being the focus nowadays. Whether he’s answering questions in the Hey, Scripting Guy! blog, posting on Twitter as @scriptingguys, speaking at various events throughout the world, or writing books, Ed is a great community resource when it comes to PowerShell! One of the events that he promotes on his blog are the Scripting Games, and the 2011 Scripting Games were no exception! This is a great contest for testing your scripting chops against other PowerShell scripters, competing in either a beginner or advanced level. What made it even neater to follow this year was that Scripting Wife joined the games. While I didn’t have time to participate this year due to other timing conflicts, I did enjoy reading the journeys of Scripting Wife as she learned working with PowerShell. Check out the Hey, Scripting Guy blog, as Ed covers some of the topics that you’ve probably wondered about.

PowerScripting Podcast

PowerScripting Podcast

Hosted by Hal Rottenberg and Jonathan Walz, the PowerScripting podcast is recorded live on UStream every Thursday night at 9:30pm Eastern Daylight Time (GMT -4). They feature various people in the PowerShell community – including talking with Jeffrey Snover (father of PowerShell), the directors of PowerShellCommunity.org, PowerShell MVPs, people on the PowerShell team, vendors of PowerShell products, and even those on product group teams whose products can benefit from PowerShell. While recording, they’ll take questions from the audience via the chat channel. I was able to catch the show on PowerShellCommunity.org, and it was neat to see how they record the podcast. After recording the show, the hosts play music while wrapping up the show – always great to rock out with these guys! Matt and I will be on PowerScripting tonight talking about our book and our love of PowerShell!
PowerShellCommunity.org

PowerShellCommunity.org

Run by the community for the community, PowerShellCommunity.org features news, forums, learning resources, steps for forming a PowerShell user group, and a poshcode.org-powered script repository. Special thanks to the sponsors of the site who provide financial support to enable the online community presence and support local PowerShell user groups – including Microsoft Windows Server 2008 R2, Quest Software, SAPIEN Technologies, Inc., Compellent, Idera, and Pragma Systems.

PowerShell.com

PowerShell.com is another community for PowerShell scripts, tips & tricks, webcasts, blogs, and other resources. Once again, Idera and Compellent are sponsoring another community resource (in addition to PowerShellCommunity.org). Concentrated Technology and nSoftware also sponsor PowerShell.com. This site also features the Master-PowerShell eBook written by Dr. Tobias Weltner. Yet another great resource for PowerShell scripters!


Get-ToThePrompt -at PowerGUI.org

PowerGUI.org

Quest Software, Inc. runs PowerGUI.org, a free community for PowerGUI users. PowerGUI is a script editor and administrative console based on PowerShell. Their community site includes tutorials, PowerPacks, forums, wikis, demos, and other goodies related to PowerGUI. If you’re using PowerGUI, then this site is a must-have resource!

#powershell on irc.freenode.net

If you’re an IRC user, definitely check out the #powershell channel on irc.freenode.net. Don’t have an IRC client? mIRC, xChat, and others are out there. Of course, freenode is awesome and has a webchat available!

Others?

These are just a few of the PowerShell resources and communities out there. Got any you want to recommend that I haven’t mentioned here? Leave me a comment!

PowerShell Not Your Father’s Command Line Part 22 of 31: Good PowerShell Things Come in Nifty Packages

Have you found yourself writing PowerShell objects that you’d love to share with others? What’s the best way to get these things distributable? Well… with PowerShell 2.0, you have two different types of packaging – snap-ins and modules.

Snap-ins

Snap-ins were available in PowerShell 1.0 and are still supported in PowerShell 2.0. In order for these to be used on a machine, they typically need to be installed first. Once the snap-in is installed on the machine, then it should be in a spot where PowerShell can see it. The best way to tell if it’s there is using the following command:

      Get-PSSnapIn -Registered

This will show all snap-ins that PowerShell can see, with the exception of those snap-ins that came with PowerShell. If the snap-in that you’ve installed doesn’t appear, then you may need to use the Installer Tool that comes with the .NET Framework to register the DLL.

Once the snap-in appears in the list, then you can bring it into the PowerShell session with the Add-PSSnapIn cmdlet. So let’s say you were installing the IIS 7.0 PowerShell snap-in,downloadable from IIS.net. Once the MSI file was run, the IIS snap-in should be installed on the computer. At this point, you should be able to run the following command:

   Add-PSSnapIn WebAdministration

While good things are already packaged in snap-ins, what if you have your own things to package in a snap-in? How do you create your own snap-in? MSDN covers this in depth.

You can also use the Import-Module cmdlet to bring in a snap-in into the PowerShell session. Tome Tanasovski covered this – including why you would choose Import-Module versus Add-PSSnapIn – in a Hey, Scripting Guy! blog post.

Modules

Modules are the newer, improved way of packaging PowerShell goodies for redistribution. Some of the goodies may include are providers, cmdlets, functions, scripts, dependent assemblies, and help files.

To see what modules are available on your machine, use the following command:

    Get-Module -ListAvailable

Unlike snap-ins, modules do not necessarily need to be installed. They need to have a certain folder structure and live within one of the directories listed in the PSModulePath environment varible.
To bring a module into your PowerShell session, use the Import-Module command. For example, if you downloaded the Windows Installer PowerShell module to use PowerShell to investigate MSI files, then you would import this module with the following command:

     Import-Module MSI

If you’re writing custom cmdlets in C#, then you’ll create a binary module – this is the DLL you create when you build your class library. If you’re writing scripts, simple functions, and advanced functions in PowerShell then you’ll create a script module, in the form of a .psm1 file. See my 4/26 presentation recap for my custom script module that is bundled with a module manifest, making it a manifest module.

The custom module that I had created shows the structure of a module, especially when help files are included. If you download the custom module, you’ll notice that the help files are simply text files. If I am redistributing a module, I typically go to the module’s folder and zip it at that level, so that the module just needs to be unzipped to one of the modules folders listed in the PSModulePath environment variable.

Matt and I have mentioned a variety of snap-ins and modules in our series so far, but there are plenty of others out there that may be useful for you. If you do a search in your favorite search engine for “PowerShell snap-in” or “PowerShell module”, you’ll be able to see what else is out there.

Seeing What’s In These Packages

While I explained how to import these snap-ins and modules into your PowerShell session, I didn’t tell you how to see what you get with them. Once your snap-in or module is in your PowerShell session, then you can use the following command to learn more about that module or snap-in:

     Get-Command -Module ModuleOrSnapInName

As always, Matt and I enjoy getting feedback on the series. If there’s something you want to see us cover, please get in touch with us. You can email me at sarah at codinggeekette dot com.

PowerShell Not Your Father’s Command Line Part 15 of 31: ISE, ISE Baby…

Here’s hoping the PowerShell community doesn’t block me from their websites for my awful taste of music. 😉

Today’s topic is the ISE, the Integrated Scripting Environment. This PowerShell host application, written in WPF, is new as of PowerShell v2.0. In this post, we will look at some of my favorite features.

Panes

As one who writes script files more than just one-off commands, I like that the ISE has 3 panes – the Script Pane, the Command Pane, and the Output Pane. The order of these panes can be toggled from a menu or via keyboard shortcuts. Here are the basics of these panes:

  • Script Pane: This a pane dedicated to editing multi-line scripts. Some of the features I particularly am fond of with the Script Pane are syntax highlighting, debugging, and tab completion.
  • Command Pane: This is a pane dedicated to run commands on demand. Think of it as the console.
  • Output Pane: This is where the commands from the Command Pane and the scripts from the Script Pane output their results.

Keyboard Shortcuts

As a developer who prefers keyboard shortcuts rather than clicking buttons, I also am super happy that the shortcuts for running and debugging scripts in the ISE match up with keyboard shortcuts in Visual Studio. These are a few keyboard shortcuts that are the same:

  • F5 – Run
  • F9 – Toggle Breakpoint
  • F10 – Step Over
  • F11 – Step In
  • Shift + F11 – Step Out

Using the ISE as an Editor

In Matt’s post on profiles, he talked of editing the $profile file with notepad. For me, I tend to run the following command to the ise alias instead when I’m in the console:

ise $profile

The reason why I like the ISE for updating my profile files is because I have syntax highlighting, as seen below:
Sarah's console profile file in the scripts pane of the ISE

A Note on ISE Profiles

Applications that host PowerShell can implement any or all of the profiles. In my post on profiles, I noted that there were 4 console profiles. The ISE has 2 profiles of its own:

  • $profile, $profile.CurrentUserCurrentHost
  • $profile.AllUsersCurrentHost


This covers some of the basics of the ISE. If you want to learn more, you can run:

Get-Help about_Windows_PowerShell_ISE

PowerShell Not Your Father’s Command Line Part 14 of 31: Sorry I’m Not Home Right Now, Walking into IIS Webs…

Sorry I’m not home right now
Walking into IIS Webs
Just leave a message and I’ll call you back – No Doubt, if they were techies

So today we’re going to look into the IIS provider in PowerShell. If you aren’t familiar with PowerShell providers, check out Matt’s post on PowerShell providers. If you’re dealing with IIS 7.0, you’ll want to look into the IIS PowerShell snap-in. Otherwise, if you’re dealing with IIS 7.5, you’ll want to look into the IIS PowerShell module. Today’s post will be looking at IIS 7.5 and the WebAdministration module.

First things, first!

In order to work with the IIS module, you need to start a PowerShell session with elevated permissions. If you don’t, then you’ll get an error like this:

PS C:userssdutkiewicz:> Import-Module WebAdministration
Process should have elevated status to access IIS configuration data.

Once you start PowerShell as an administrator, you can use Get-Module to see if the WebAdministration module is loaded. If it isn’t loaded, then run:

Import-Module WebAdministration

The module is loaded. What kind of goodies are in the IIS module?

A lot of IIS functionality that you’re used to in the GUI is also available in the WebAdministration module, packed into a variety of cmdlets. There are cmdlets to help with:

  • web configuration
  • websites
  • web applications
  • application pools
  • web bindings

To see a full list of cmdlets, aliases, and functions included in the WebAdministration module, run the following command:

Get-Command -Module WebAdministration

You mentioned an IIS provider…

Yes, I did! If you run the following command, you’ll see a list of providers installed:

Get-PSProvider

You should see a provider named WebAdministration, which includes an IIS drive. Let’s see what it allows us to explore.

Set-Location IIS:

If we run a Get-ChildItem at this point, we’ll see that the IIS provider lets us navigate through 3 parts of IIS – AppPools, Sites, and SslBindings. Today, we’ll look at Sites, as they are the central point. The Sites folder in the IIS provider contains websites, web applications, and virtual directories. From the IIS: prompt, run the following command:

Set-Location Sites

If you run the Get-ChildItem command at this point, you should see the list of sites setup on your web server. It may look like the picture below:

Sarah's demo websites

You’ll notice that my sadukievents site shows a state of being stopped. We can easily fix this using one of the cmdlets included in the WebAdministration module:

Start-Website sadukievents

Notice how simple it was – no need to remember an IIS metabase path! Now let’s say that same site was getting carried away with the resources and we needed to stop the site. The Stop-Website cmdlet works similarly. Of course, sites rarely misbehave at an appropriate time. When you open PowerShell as an administrator, you’re dropped at your system folder (unless you’ve altered that). Rather than changing to the IIS drive and stopping the site (whose name you already know), you can run this command from your current drive with the following command:

Stop-Website sadukievents

Now back to IIS:Sites… what do you see once you change directories into a Site? When you run Get-ChildItem (or its built-in alias of dir) on a site, it shows you the contents of the site. The image below shows what’s in the sadukievents website:

directory listing of the sadukievents website

You can see that the output from this particular folder looks like a directory listing – showing the file mode, last write time, length, and name. This appears this way because these are all files or directories. What if there was a virtual directory or possibly a web application in this folder? Then the output changes to show the type (application, directory, file, or virtualDirectory), name, and physical path. You can see a sample of this below:

directory listing of the sadukievents website with modules and virtual directories

At this point, you should feel comfortable navigating through the Sites folder. You can use Get-ChildItem and Set-Location to navigate through the AppPools and SslBindings folders in the same way, learning more about the AppPools and SslBindings.

So that’s navigation. Can we do anything else in here?

Besides navigating the IIS drive, you can also use it much like you would other PowerShell provider drives. When working with IIS cmdlets from outside of the IIS drive, you can reference the IIS drive as a path. For example, let’s say you’re working in a clustered web environment due to high-availability requirements and need to setup a new website on all the servers in the cluster. Sure, you could do it manually on each server, but why waste your time when you can script it? Here’s a sample command for creating a new web application:

New-Item ‘IIS:SitesSadukieville’ -Type Application -PhysicalPath d:WebsitesSadukieville

If that example web application had a virtual directory for a bakery site within it, it may be scripted like this:

New-Item ‘IIS:SitesSadukievilleBakery’ -Type VirtualDirectory -PhysicalPath c:inetpubwwwRootsadukieria

Both of the above examples show how you can use the IIS provider as a path with other cmdlets. Of course, there’s plenty more that you can do. For more information, explore the cmdlets as suggested above, and know that Get-Help and Get-Help command -examples are at your fingertips to guide you through how those cmdlets work and how you can take advantage of the IIS provider while scripting your web administration tasks.


Do you have specific questions about PowerShell that you want answered? Whether it’s IT pro related or developer related, I can probably help! Drop me a line at sarah at codinggeekette dot com, and I’ll try to cover your questions in an upcoming blog post.

Matt and I love feedback from our readers, so please email us if you have comments or suggestions.

PowerShell Not your Father’s Command Line Part 13 of 31: The Provider Active Directory Style

Matt and I really are huge fans of PowerShell providers. After talking about them in general and focusing on the registry provider, you think that we’d stop. But no… there are two more days of this talk of providers – Matt is going to talk about the Active Directory provider today, and I’m going to talk about the IIS provider tomorrow. Yes, providers make our administration tasks much easier by getting us access to things that are typically a little harder to script. This makes it easier for IT pros to write scripts that take advantage of these providers and automate more of their day-to-day operations.

Do you have a favorite provider? Tell us about it! Leave us comments on our blogs or email us. You can reach me at sarah at codinggeekette dot com.

PowerShell Not your Father’s Command Line Part 12 of 31: PowerShell and The Registry

Yesterday, Matt and I talked about providers, and I mentioned that I wasn’t going to go on talking about the registry provider, as that’s what Matt is talking about today! What’s nice is that you don’t have to type out HKEY_LOCAL_MACHINE and HKEY_CURRENT_USER while working with this provider. You can refer to them by HKLM and HKCU, respectively.

However, those are the only 2 registry hives that are provided for. So if you are working with the other hives (HKEY_CLASSES_ROOT, HKEY_USERS, and HKEY_CURRENT_CONFIG), you will have to rely on your previous knowledge of accessing them to work with them. There are no HKCR, HKU, or HKCC drives to help out in this case.

PowerShell Not your Father’s Command Line Part 11 of 31: PowerShell Providers and You!

Today, Matt is going to tell you about the awesomeness known as PowerShell providers. I have to admit that providers really are helpful. Sure, there are the PowerShell-specific providers – Alias, Function, and Variable. These can tap into the PowerShell system and help you determine what aliases, functions, and variables already exist. But then there are other providers that are there to make it easier to access data stores that are typically hard to access in a scripting environment.

Matt will talk about the registry provider tomorrow, so I won’t go on about it here. The other built-in providers give us access to the file system objects (FileSystem provider), X.509 certificate store (Certificate provider), environment variables (Environment provider), and Web Services for Management (WSMan provider).

When Matt and I were working on our book, I had the joys of playing with providers and figuring out how they work under the covers. I won’t scare you off from them by showing you code here – that’s in Appendix C of our book. However, if you want to get into provider development more extensively after reading our book, I recommend talking with Oisin Grehan, the coordinator of the PowerShell Script Provider project on CodePlex, which will allow you to write a custom provider in PowerShell. (Yes, a provider to create providers!)