Creating objects in PowerShell is… strange, to put it lightly–down right awful if you want to be realistic. But even if the syntax is terrible, objects are still nice to use. Here’s a quick primer on how to create and use an object in PowerShell.
The PowerShell WebAdministration module can be finicky. If you’re seeing COMException error messages, here are a few things you could try.
WebAdministration Errors
If you import the module using the 32-bit version of PowerShell, you might see the following.
PS > Import-Module WebAdministration
PS > Get-Website
Get-Website : Retrieving the COM class factory for component with CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} failed
due to the following error: 80040154.
At line:1 char:12
+ Get-Website < <<<
+ CategoryInfo : NotSpecified: (:) [Get-Website], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.IIs.PowerShell.Provider.GetWebsite
Command
If you import the module using the 64-bit version of PowerShell, you might see this error.
PS > Import-Module WebAdministration
PS > Get-Website
format-default : Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
+ CategoryInfo : NotSpecified: (:) [format-default], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.PowerShell.Commands.FormatDefaultCommand
I’m still somewhat new to PowerShell and all the time I find myself wanting to examine objects to see what properties and methods they have available. The documentation on MSDN and around the web is pretty good, but there are still plenty of situations where it’s just easier or better to ask PowerShell to help you out instead. For instance, when you’re using a third-party module that’s sparsely documented you might want to just examine its objects. Or maybe you just don’t feel like going to Google. Either way, here’s a bunch of ways you can get a better look at an object in PowerShell.
I recently added PowerShell to my repertoire and noticed it has quite a few interesting quirks. The syntax is a bit odd as well, but overall it’s a pretty handy language to know and it definitely has a place in any developer’s toolkit.
Understanding the ins and outs of PowerShell did require quite a bit of Googling and practice, so I thought it might be nice to document some of what I found and put together a PowerShell for Programmers primer.