像这样的代码,
try { $NIC = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $Computername -Credential $Credential -filter "IPEnabled = $TRUE" }
catch [GetWMICOMException]
{
"Error 1"
}
catch [System.UnauthorizedAccessException]
{
"Error 2"
}
收到如下错误:
找不到类型 [GetWMICOMException]:
捕捉 [COMException] 相同
catch [System.Runtime.InteropServices.COMException] 只是被忽略了
我怎么能抓住它?
Get-WmiObject : RPC server was unavailable. (Exception HRESULT: 0x800706BA)
F:\PowerShell Scripts\Project1.NetReconfigurer\proj1.ps1:36 :33
+ $NIC = Get-WmiObject <<<< Win32_NetworkAdapterConfiguration -ComputerName $Computername -Credential $Credential -filter "IPEnabled = $TRUE"
+ CategoryInfo : InvalidOperation: (:) [Get-WmiObject], COMException
+ FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand