我正在使用一个脚本在PC(服务器上的目标文件夹)上创建扫描文件夹快捷方式,但是PC超过1000+。 以下脚本一个接一个地工作良好,我想提高效率并缩短时间。 我有什么办法可以同时并行调用它们? 一个例子将不胜感激。谢谢
调用命令-ComputerName'PC001','PC002'-ScriptBlock {Register-PSSessionConfiguration -RunAsCredential'domain \ user'-名称测试-Force}
调用命令-ComputerName'PC001','PC002'-FilePath'C:\ temp \ create扫描快捷方式.ps1'-ConfigurationName测试
#get server name and pc name
$PCname = $env:computername
$Servername = $PCname.Substring(0,9)+"P001"
#create shortcut on C:\
$SourceFileLocation = "\\$Servername\Scan"
$ShortcutLocation = "C:\Scan.lnk"
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutLocation)
$Shortcut.TargetPath = $SourceFileLocation
$Shortcut.Save()
#test path
$path = Test-Path -path "C:\Scan.Lnk"
if ($path -eq 'True'){
Write-Host "$PCname Scan folder already existed" -ForegroundColor Green
}
else{
Write-Host "$PCname Scan folder does not exist" -ForegroundColor Red
}
答案 0 :(得分:1)
此做并行运行。它将等到它们全部完成,但是它们同时运行。
invoke-command localhost,localhost,localhost { sleep 10 }
get-history | select -last 1 | fl
Id : 9
CommandLine : invoke-command localhost,localhost,localhost { sleep 10 }
ExecutionStatus : Completed
StartExecutionTime : 6/10/2020 12:53:37 PM
EndExecutionTime : 6/10/2020 12:53:50 PM