Hello All
Can someone please help me with the following question.
I am trying to be more specifc when catching exceptions
if I do the following
Get-WmiObject -ComputerName Server1 -Class Win32_PowerPlan -Namespace "root\cimv2\power" -ErrorAction stop | where {$_.IsActive}
that works fine if the Server in question has the relevent WMI namespace. Some of my older Servers to not and therefore the following exception is thrown
Get-WmiObject : Invalid namespace
At line:1 char:14
+ Get-WmiObject <<<< -ComputerName Server1 -Class Win32_PowerPlan -Namespace "root\cimv2\power" -ErrorAction stop | where {$_.IsActive
+ CategoryInfo : InvalidOperation: (:) [Get-WmiObject], ManagementException
+ FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
OK, so if I do
try {
Get-WmiObject -ComputerName Server1 -Class Win32_PowerPlan -Namespace "root\cimv2\power" -ErrorAction stop | where {$_.IsActive}
}
catch [exception] {"there was an exception"}
that works OK too, however I want to catch a more specifc and therfore relevent exception from the above error, I have tried
catch [Microsoft.PowerShell.Commands.GetWmiObjectCommand]
catch [GetWMIManagementException]
catch [ManagementException]
no Cigar any advise/suggests please
Thanks All
Ernie