【问题标题】:Powershell: Remove-Item - path throwing error at integersPowershell:Remove-Item - 整数路径抛出错误
【发布时间】:2022-07-11 23:54:31
【问题描述】:

这是一个相对较短的,但似乎无法弄清楚计算机如何能够以不同的方式看到这一点。我有一个要使用 Powershell 删除的文件夹,但 Remove-Item 函数抛出错误,因为路径包含 Program Files (x86)

见以下代码:

Invoke-Command -ComputerName $computer {Remove-Item -Path C:\Program Files (x86)\Microsoft\Test -Force -Verbose}

它不喜欢程序文件在 x86 周围有括号的事实。当我在路径周围加上引号时,它根本无法识别它。

我怎样才能解决这个问题?

【问题讨论】:

    标签: powershell


    【解决方案1】:

    这可能会有所帮助 https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_quoting_rules?view=powershell-7.2

    但答案是

    Invoke-Command -ComputerName $computer {Remove-Item -Path 'C:\Program Files (x86)\Microsoft\Test' -Force -Verbose}
    

    【讨论】:

    • 谢谢!正在寻找类似的东西
    【解决方案2】:

    您的问题是使用双引号。使用单引号停止将括号解释为自己的子句/语句。

    Invoke-Command -ComputerName $computer {Remove-Item -Path 'C:\Program Files (x86)\Microsoft\Test' -Force -Verbose}
    

    【讨论】:

      猜你喜欢
      • 2013-03-24
      • 2011-04-18
      • 1970-01-01
      • 2014-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-27
      • 1970-01-01
      相关资源
      最近更新 更多