Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.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
powershell:如何在抛出异常时仅显示消息?_Powershell_Throw - Fatal编程技术网

powershell:如何在抛出异常时仅显示消息?

powershell:如何在抛出异常时仅显示消息?,powershell,throw,Powershell,Throw,我需要在找不到目录时抛出一个异常,并抑制详细信息 if( ! (Test-Path -Path $destDir) ) { throw "Directory $destDir not found!" } 在这种情况下,将显示消息和详细信息,在代码中抛出该消息 有没有办法只显示消息而不显示细节 (我测试了throw…2>$null,但这不起作用)在catch块中使用$\uuxception.Message。更多信息。您可以使用写入错误和退出/中断@Paul write error也会

我需要在找不到目录时抛出一个异常,并抑制详细信息

if( ! (Test-Path -Path $destDir)  )
{
    throw "Directory $destDir not found!" 
}
在这种情况下,将显示消息
和详细信息
,在代码中抛出该消息

有没有办法只显示消息而不显示细节


(我测试了
throw…2>$null
,但这不起作用)

在catch块中使用
$\uuxception.Message
。更多信息。

您可以使用
写入错误
退出
/
中断
@Paul write error也会显示详细信息。我的解决方案是使用
写主机“目录丢失”-ForegroundColor Red
。谢谢我在你的链接中找到了我需要的解决方案:
写主机“目录丢失”-ForegroundColor红色
,然后
退出
。我不需要抛出异常。典型的新手不知道概念问题。谢谢