Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 为什么PS不接球:“为什么PS不接球?”;新建PSDrive:登录失败:未知用户(…)“;?_.net_Powershell_Powershell 2.0_Powershell 3.0 - Fatal编程技术网

.net 为什么PS不接球:“为什么PS不接球?”;新建PSDrive:登录失败:未知用户(…)“;?

.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 # (..

我有一个PowerShell模块

在模块中,我通过try…catch块处理异常。 但由于某些原因,当我在创建新PSDrive时提供错误密码时,控制台上会出现以下错误:

“新PSDrive:登录失败:未知用户(…)”

但是try..catch块未捕获它,请重新尝试:

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