【问题标题】:How to set variable in a Powershell command?如何在 Powershell 命令中设置变量?
【发布时间】:2022-01-27 19:54:29
【问题描述】:

在我的项目中,我有一段执行命令的代码:

Remove-Item -path \\D$\folder_name\* -recurse -force 

有没有办法将路径保存到变量中?

类似:

Remove-Item -path ${path} -recurse -force 

【问题讨论】:

    标签: powershell command-line


    【解决方案1】:

    你可以像这样创建一个变量:

    $Path = "\\$\folder_name\*"
    

    然后将其传递给 Remove-Item cmdlet:

    Remove-Item -Path $Path -Recurse -Force
    

    【讨论】:

      猜你喜欢
      • 2018-06-18
      • 2018-11-25
      • 2018-01-01
      • 2012-07-22
      • 2020-06-06
      • 1970-01-01
      • 2019-06-30
      • 1970-01-01
      • 2012-09-05
      相关资源
      最近更新 更多