powershell - "("字符在 PowerShell 中不起作用

标签 powershell

我不能让它工作。它不喜欢“(”字符;

我如何解决它?

 Dir | Rename-Item -NewName { $_.name -replace "(","" }

如何在 PowerShell 中处理此类特殊字符?

最佳答案

@vonPryze 对您问题的确切原因有很好的解释,但有一个更简单的解决方案。 -replace运算符使用需要转义的正则表达式,但 .Replace() string 方法只使用字符串。因此,如果您不需要正则表达式,只需使用该方法,无需转义任何内容:

dir | rename-item -NewName { $_.name.Replace("(","") }

关于powershell - "("字符在 PowerShell 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21824026/

相关文章:

powershell - 如何通过Powershell检索IAM实体限制和当前使用情况

powershell - WinRM 无法完成操作。验证指定的计算机名称是否有效

powershell - 通过管道将 0..10 连接到高级函数

azure - New-AzureADApplicationPasswordCredential 引发 Authorization_RequestDenied

powershell - 为 Azure 资源管理器模板部署 DSC 扩展时出现问题

windows - Out-File 不写任何输出

powershell - PowerShell:导入CSV文件,计数组大小和输出到原始文件,并在计数后添加新列

powershell - 在 PowerShell 脚本中使用括号?

powershell - 错误:An attempt was made to add an object to the directory with a name that is already in use

powershell - 如何在 PowerShell 中标准化路径?