.net 为什么PS不接球:“为什么PS不接球?”;新建PSDrive:登录失败:未知用户(…)“;?
我有一个PowerShell模块 在模块中,我通过try…catch块处理异常。 但由于某些原因,当我在创建新PSDrive时提供错误密码时,控制台上会出现以下错误: “新PSDrive:登录失败:未知用户(…)” 但是try..catch块未捕获它,请重新尝试:.net 为什么PS不接球:“为什么PS不接球?”;新建PSDrive:登录失败:未知用户(…)“;?,.net,powershell,powershell-2.0,powershell-3.0,.net,Powershell,Powershell 2.0,Powershell 3.0,我有一个PowerShell模块 在模块中,我通过try…catch块处理异常。 但由于某些原因,当我在创建新PSDrive时提供错误密码时,控制台上会出现以下错误: “新PSDrive:登录失败:未知用户(…)” 但是try..catch块未捕获它,请重新尝试: try { # (...) New-PSDrive -name $myDrive -PSProvider FileSystem -Root $sharedLocation -Credential $credentials # (..
try {
# (...)
New-PSDrive -name $myDrive -PSProvider FileSystem -Root $sharedLocation -Credential $credentials
# (...) s
}
catch [System.Exception]
{
$message = "ERROR : Occured "
Write-Error $message
throw $_
}
问题:
有什么建议说明我为什么无法捕获此错误吗?此错误可能不是终止错误,因此无法捕获。尝试使用ErrorAction参数,使错误成为终止错误
New-PSDrive -name $myDrive ... -ErrorAction Stop
该错误可能不是终止错误,因此无法捕获。尝试使用ErrorAction参数,使错误成为终止错误
New-PSDrive -name $myDrive ... -ErrorAction Stop