首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >脚本启动脚本-限制并发脚本的数量

脚本启动脚本-限制并发脚本的数量
EN

Stack Overflow用户
提问于 2019-04-25 20:10:20
回答 1查看 42关注 0票数 0

我正在尝试启动许多并发的PowerShell脚本。在Windows会话锁定或断开连接之前,以下逻辑运行正常。一旦发生这种情况,脚本就会毫不留情地启动每个脚本,而不管进程数是多少。

代码语言:javascript
复制
foreach ($Script in $Scripts) {
    if ((Get-Process powershell -ErrorAction SilentlyContinue).Count -lt 10) {
        Start-Process powershell.exe -ArgumentList "-File `"$Script`""
        Start-Sleep -s 5
    } else {
        while ((Get-Process powershell -ErrorAction SilentlyContinue).Count -lt 10) {
            Start-Sleep -s 30
        }
        Start-Process powershell.exe -ArgumentList "-File `"$Script`""
        Start-Sleep -s 5
    }
}
EN

回答 1

Stack Overflow用户

发布于 2019-04-25 21:07:37

我使用下面的简单powershell代码来运行文件夹中的脚本。你可以修改它

代码语言:javascript
复制
################################################
### Auto-load scripts on PowerShell startup ###
# directory where my scripts are stored
################################################

$psdir="C:\work\JumpStart\Autoload"  

Write-Host "Custom PowerShell Environment Start Loading" 
Write-Host " " 

# load all 'autoload' scripts
Get-ChildItem "${psdir}\*.ps1" | %{.$_}  
Get-ChildItem "${psdir}\*.ps1" | %{Write-host $_}  

Write-Host " " 
Write-Host "Custom PowerShell Environment Loaded" 

################################################
### Auto-load scripts on PowerShell startup ###
################################################
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55849024

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档