我想避免由空dsquery引起的错误。我尝试了这个:

try {
     dsquery user forestroot -samid $a[$i] | dsget user -email | Select-String '@' | select -Expand Line >> output.txt
}
catch [Exception] {
    return $_.Exception.Message
}

但是我仍然得到:
dsget : dsget failed:'Target object for this command' is missing.
At ExpiringCertificates.ps1:35 char:49
+         dsquery user forestroot -samid $a[$i] | dsget user -email | Select-Strin ...
+                                                 ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (dsget failed:'T...nd' is missing.:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

type dsget /? for help.

我应该如何处理?

最佳答案

这可能对您有用:

try {
     $erroractionpreference = 'stop'
     dsquery user forestroot -samid $a[$i] | dsget user -email | Select-String '@' | select -Expand Line >output
}
catch [Exception] {
    return $_.Exception.Message
}

关于powershell - 由空dsquery引起的PowerShell中的错误处理,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22831141/

10-13 06:55