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