gpt4 book ai didi

powershell - 将简单的PowerShell命令添加到批处理文件

转载 作者:行者123 更新时间:2023-12-03 01:14:00 25 4
gpt4 key购买 nike

我试图将几个简单的PowerShell命令添加到批处理文件中。我的首选是保持批处理文件自包含而不是调用外部.ps1文件。

任务:

从特定文件夹结构的文件名中删除& char。

以下PowerShell命令可从命令行使用:

cd c:\Media\Downloads
Get-ChildItem -Filter '*&*' -Recurse | Rename-Item -NewName {$_.name -replace '&','testing' }"

这是我尝试添加到批处理文件中的尝试,但没有成功:
 %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -command "& cd c:\Media\Downloads"
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -command "& Get-ChildItem -Filter '*&*' -Recurse | Rename-Item -NewName {$_.name -replace '&','testing' }"

任何人都可以提供一些建议吗?

最佳答案

powershell -c "Get-ChildItem 'c:\Media\Downloads' -Filter '*&*' -Recurse | Rename-Item -NewName {$_.name -replace '&','testing' }"
  • Get-ChildItem中指定路径
  • 无需指定powershell
  • 的完整路径

    关于powershell - 将简单的PowerShell命令添加到批处理文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33809252/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com