Powershell 在递归文件夹中运行exe
这应该在根目录和Powershell 在递归文件夹中运行exe,powershell,windows-7,Powershell,Windows 7,这应该在根目录和$start\u path的所有子文件夹中运行VST\u Screenshot\u Tool.exe。我得到这个错误: 表达式仅允许作为管道的第一个元素。 在C:\Users\pithy\Desktop\screenshotter.ps1:2 char:13 +$start\u path$start\u path>Get ChildItem Recurse将字符串D:\VST\写入当前目录中的文件Get ChildItem Recurse。此外,执行命令字符串需要调用操作符(&)
$start\u path
的所有子文件夹中运行VST\u Screenshot\u Tool.exe
。我得到这个错误:
表达式仅允许作为管道的第一个元素。
在C:\Users\pithy\Desktop\screenshotter.ps1:2 char:13
+$start\u path$start\u path>Get ChildItem Recurse
将字符串D:\VST\
写入当前目录中的文件Get ChildItem Recurse
。此外,执行命令字符串需要调用操作符(&
),如果要运行外部命令,则应包括扩展名。如果没有操作符,PowerShell将简单地回显字符串
将代码更改为:
Set-ExecutionPolicy Unrestricted
$start_path ="D:\VST\"
$start_path> Get-ChildItem-Recurse |
foreach { cd $_.DirectoryName; "VST_Screenshot_Tool"; cd ..; }
在PowerShell v2及更早版本上,您需要将-Directory
参数替换为如下:
$start_path = 'D:\VST'
Get-ChildItem $start_path -Recurse -Directory | ForEach-Object {
Set-Location $_.FullName
& "VST_Screenshot_Tool.exe"
}
Get-ChildItem $start_path -Recurse | Where-Object {
$_.PSIsContainer
} | ForEach-Object {
Set-Location $_.FullName
& "VST_Screenshot_Tool.exe"
}