powershell - 如何使powershell在错误上不那么冗长?

标签 powershell

例如,考虑以下控制台记录:

PS C:\dev\windows> rmdir -Recurse .\bin
Remove-Item : Cannot remove item C:\dev\windows\bin\DotNet\Debug\Implementation\Common.DTO.XML: Access to the path 'Common.DTO.XML' is denied.
At line:1 char:6
+ rmdir <<<<  -Recurse .\bin
    + CategoryInfo          : PermissionDenied: (Common.DTO.XML:FileInfo) [Remove-Item], UnauthorizedAccessException
    + FullyQualifiedErrorId : RemoveFileSystemItemUnAuthorizedAccess,Microsoft.PowerShell.Commands.RemoveItemCommand
Remove-Item : Directory C:\dev\windows\bin\DotNet\Debug\Implementation cannot be removed because it is not empty.
At line:1 char:6
+ rmdir <<<<  -Recurse .\bin
    + CategoryInfo          : WriteError: (Implementation:DirectoryInfo) [Remove-Item], IOException
    + FullyQualifiedErrorId : DirectoryNotEmpty,Microsoft.PowerShell.Commands.RemoveItemCommand

Remove-Item : Cannot remove item C:\dev\windows\bin\DotNet\Debug\Shunra.Common.Contract.XML: Access to the path 'Shunra.Common.Contract.XML' is denied.
At line:1 char:6
+ rmdir <<<<  -Recurse .\bin
    + CategoryInfo          : PermissionDenied: (Shunra.Common.Contract.XML:FileInfo) [Remove-Item], UnauthorizedAccessException
    + FullyQualifiedErrorId : RemoveFileSystemItemUnAuthorizedAccess,Microsoft.PowerShell.Commands.RemoveItemCommand
Remove-Item : Cannot remove item C:\dev\windows\bin\DotNet\Debug\Shunra.Common.XML: Access to the path 'Shunra.Common.XML' is denied.
At line:1 char:6
+ rmdir <<<<  -Recurse .\bin
    + CategoryInfo          : PermissionDenied: (Shunra.Common.XML:FileInfo) [Remove-Item], UnauthorizedAccessException
    + FullyQualifiedErrorId : RemoveFileSystemItemUnAuthorizedAccess,Microsoft.PowerShell.Commands.RemoveItemCommand
Remove-Item : Directory C:\dev\windows\bin\DotNet\Debug cannot be removed because it is not empty.
At line:1 char:6
+ rmdir <<<<  -Recurse .\bin
    + CategoryInfo          : WriteError: (Debug:DirectoryInfo) [Remove-Item], IOException
    + FullyQualifiedErrorId : DirectoryNotEmpty,Microsoft.PowerShell.Commands.RemoveItemCommand

Remove-Item : Directory C:\dev\windows\bin\DotNet cannot be removed because it is not empty.
At line:1 char:6
+ rmdir <<<<  -Recurse .\bin
    + CategoryInfo          : WriteError: (DotNet:DirectoryInfo) [Remove-Item], IOException
    + FullyQualifiedErrorId : DirectoryNotEmpty,Microsoft.PowerShell.Commands.RemoveItemCommand

Remove-Item : Directory C:\dev\windows\bin cannot be removed because it is not empty.
At line:1 char:6
+ rmdir <<<<  -Recurse .\bin
    + CategoryInfo          : WriteError: (C:\dev\windows\bin:DirectoryInfo) [Remove-Item], IOException
    + FullyQualifiedErrorId : DirectoryNotEmpty,Microsoft.PowerShell.Commands.RemoveItemCommand

PS C:\dev\windows>

现在将它与普通shell(cmd.exe)进行比较:
C:\dev\windows>rmdir /s/q bin
bin\DotNet\Debug\IMPLEM~1\Common.DTO.XML - Access is denied.
bin\DotNet\Debug\Shunra.Common.Contract.XML - Access is denied.
bin\DotNet\Debug\Shunra.Common.XML - Access is denied.

C:\dev\windows>

区别很明显,我更喜欢 cmd.exe 的简洁,而不是 powershell 的冗长。

我可以在 powershell 中具有相同的简洁性吗?如果不是针对所有命令,那么也许只是针对我经常使用的 Remove-Item?

最佳答案

您可以获得的最接近的结果是将全局 $ErrorView 值更改为“CategoryView”。另一种方法是创建自己的 View 。

关于powershell - 如何使powershell在错误上不那么冗长?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7771495/

相关文章:

powershell - 如何在PowerShell 3.0中编写此多行语句

powershell - 为什么对伪造数组属性的逻辑测试会返回 true?

Azure - 在 Powershell 中断开 VNet 集成

powershell - CMD:如何在 cmd 中转义此 powershell 命令?

security - 如何设置系统日期/时间而不提示 UAC

tsql - Invoke-Sqlcmd有时会报告TSQL错误,有时却不会。

arrays - 使用数组索引中的变量输出 $Error

PowerShell 脚本 - 区分 3 个命令结果

powershell - 基本 PowerShell 脚本问题 : "Expressions are only allowed as the first element of a pipeline"

arrays - Powershell验证我的数组元素类型