在目录中运行所有 PowerShell 脚本 [英] Run All PowerShell Scripts In A Directory
本文介绍了在目录中运行所有 PowerShell 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在一个目录中有一系列 ps1 文件,所有这些文件都有不同的名称.我正在尝试使用 Start-Process
和 -Wait
参数一个接一个地运行它们.如何遍历目录中的所有文件并一个接一个地运行 PowerShell 脚本?没有子文件夹,也没有非 ps1 类型的文件.
I have a series of ps1 files in a directory, all of which have different names. I am trying to run them one after another with Start-Process
and the -Wait
parameter. How does loop through all the files in a directory and run one PowerShell script after another? There are no subfolders, and no files that are not of type ps1.
这是我的开始:
$DirectoryList = Get-Content -Path C:\test
foreach ($Directory in $DirectoryList) {
Start-Process -FilePath powershell.exe -ArgumentList ('"{0}\How To Read Me.ps1" -Path "{1}"' -f $PSScriptRoot, $Directory);
}
推荐答案
您可以简单地使用 呼叫运算符 (&
):
You could simply use the call operator (&
):
Get-ChildItem 'C:\test' | ForEach-Object {
& $_.FullName
}
这篇关于在目录中运行所有 PowerShell 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文