相关疑难解决方法(0)

如何在不使用作业的情况下并行运行我的 PowerShell 脚本?

如果我有一个脚本需要在多台计算机上运行,​​或者有多个不同的参数,我如何并行执行它,而不必产生产生新PSJobStart-Job的开销?

例如,我想重新同步所有域成员的时间,如下所示:

$computers = Get-ADComputer -filter * |Select-Object -ExpandProperty dnsHostName
$creds = Get-Credential domain\user
foreach($computer in $computers)
{
    $session = New-PSSession -ComputerName $computer -Credential $creds
    Invoke-Command -Session $session -ScriptBlock { w32tm /resync /nowait /rediscover }
}
Run Code Online (Sandbox Code Playgroud)

但我不想等待每个 PSSession 连接并调用命令。如果没有乔布斯,这如何并行完成?

automation powershell performance

32
推荐指数
2
解决办法
5万
查看次数

标签 统计

automation ×1

performance ×1

powershell ×1