gpt4 book ai didi

powershell - 在目录中运行所有 PowerShell 脚本

转载 作者:行者123 更新时间:2023-12-02 05:23:56 25 4
gpt4 key购买 nike

我在一个目录中有一系列 ps1 文件,所有这些文件都有不同的名称。我试图用 Start-Process 一个接一个地运行它们和 -Wait范围。如何遍历目录中的所有文件并一个接一个地运行 PowerShell 脚本?没有子文件夹,也没有不是 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);
}

最佳答案

您可以简单地使用 call operator ( & ):

Get-ChildItem 'C:\test' | ForEach-Object {
& $_.FullName
}

关于powershell - 在目录中运行所有 PowerShell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27851292/

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