Hi All,
Below script transfer the data one after another complete the Job. i need to run the job parallels on multiple server
how to run the jobs for multiple servers parallely?
param (
#[string]$SourceFolderPath, # Source folder path (e.g., C:\path\to\folder)
[string[]]$DestinationServers # Array of destination server names (e.g., "ServerB", "ServerC")
)
function transfer{
param (
#[string]$SourceFolderPath, # Source folder path (e.g., C:\path\to\folder)
[string]$DestinationServers # Array of destination server names (e.g., "ServerB", "ServerC")
)
Import-Module BitsTransfer
$Source="F:\Infrastructure\ARGONInfra\SCCM2012\WS2019\Packages\HyperV2019 Installer 2212\Binaries"
$Destination="\\$DestinationServers\p$\HyperV2019_Installer_2212"
if ( -Not (Test-Path $Destination))
{
$null = New-Item -Path $Destination -ItemType Directory
}
$folders = Get-ChildItem -Name -Path $source -Directory -Recurse
foreach ($i in $folders)
{
$exists = Test-Path $Destination\$i
if ($exists -eq $false)
{
New-Item $Destination\$i -ItemType Directory
}
$Job = Start-BitsTransfer -DisplayName $DestinationServers -Source $Source\$i\*.* -Destination $Destination\$i -asynchronous -Priority low
return $Job
}
}
# Create an array to store the BITS transfer jobs
$BitsJobs = @()
# Loop through each destination server and initiate folder transfer as a job
foreach ($server in $DestinationServers) {
$bitsJob = transfer -DestinationServer $server
$BitsJobs += $bitsJob
}
# Wait for all BITS transfer jobs to complete
Write-Host "Waiting for BITS transfer jobs to complete... $server"
$BitsJobs | ForEach-Object {
do {
Write-Host "Job State for $($_.JobDisplayName): $($_.JobState)"
Start-Sleep -Seconds 5
$_ = Get-BitsTransfer -JobId $BitsJobs.JobId
} while ($_.JobState -eq "Transferring" -or $_.JobState -eq "Connecting")
}
Write-Host "All BITS transfer jobs completed."
Thanks
Manikandan.K