Skip to content

Instantly share code, notes, and snippets.

@daisyUniverse
Created August 7, 2025 20:03
Show Gist options
  • Save daisyUniverse/fbc2d01530a3b79898e9fab910959757 to your computer and use it in GitHub Desktop.
Save daisyUniverse/fbc2d01530a3b79898e9fab910959757 to your computer and use it in GitHub Desktop.
Leverage SCCM in transferring large folders over the network to a large device collection
# CAD BLASTER 25
# Copy some folders to the cad machines at all costs
# Robin Universe [S]
# 08 . 07 . 25
param(
[string]$Source,
[string]$Target = "temp\",
[string]$Collection = "CAD Computers",
[string]$Site = "ABC:\\"
)
# Get every machine name in a given collection.
function Resolve-Collection(){
Write-Host " Resolving the computer names in the collection: " -NoNewline -ForegroundColor Yellow; Write-Host "'$Collection...'" -ForegroundColor Green
$currentPath = Get-Location
cd $Site
$coms = (Get-CMCollectionMember -CollectionName $Collection).Name
cd $currentPath
return $coms
}
# Tell SCCM to wake the target collection
function Wake-Collection([switch]$OneShot) {
if(!$OneShot){ Write-Host " Using SCCM to wake the collection " -NoNewline -ForegroundColor Yellow; Write-Host "'$Collection'..." -ForegroundColor Green }
$currentPath = Get-Location
cd $Site
Invoke-CMClientAction -ActionType ClientNotificationWakeUpClientNow -CollectionName $Collection
cd $currentPath
$t = 0; while ($t -lt 120) {
Write-Host "`r [ $t ] Waiting 2 Minutes to let computers wake up... (press Q to skip)" -ForegroundColor Yellow -NoNewline; Start-Sleep 1; $t++
if ([System.Console]::KeyAvailable) {$key = [System.Console]::ReadKey($true); if ($key.KeyChar -eq 'q'){$t=119}}
}
Write-Host
if(!$OneShot){ Ping-Collection } else { Write-Host " -- Oneshot Wakeup Invoked -- " -ForegroundColor Blue }
}
# Ping all machines in the collection to ensure they are online and ready to rock
function Ping-Collection(){
$coms = Resolve-Collection
Write-Host " Pinging machines in resolved computer names..." -ForegroundColor Yellow
$comsOnline = @()
foreach ($com in $coms) {
Write-Host "`r [ $com ] Pinging... " -ForegroundColor Yellow -NoNewline;
$Online = Test-Connection $com -Count 1 -Quiet; Sleep -Milliseconds 33
if ($Online) {
Write-Host "`r [ $com ] ONLINE " -ForegroundColor GREEN -NoNewline; Sleep -Milliseconds 33
$comsOnline += $com
} else {
Write-Host "`r [ $com ] OFFLINE " -ForegroundColor RED -NoNewline; Sleep -Milliseconds 33
}
}
$x = ($coms.Length - $comsOnline.Length ); $y = $coms.Length
if ($x -ne $y){
Write-Host "`r [ " -NoNewline ; Write-Host "$x" -ForegroundColor Red -NoNewline; Write-Host " / " -NoNewline; Write-Host "$y" -ForegroundColor Green -NoNewline; $answer = Read-Host " ] computers offline. try again? [y/N]"
if ($answer -like 'y') { Wake-Collection } else {
return $comsOnline
}
} else {
return $comsOnline
}
}
function Copy-Files($Online){
Write-Host " Beginning the file transfers! " -ForegroundColor Yellow
foreach ($com in $Online){
try {
Write-Host "`r [ $com ] Copying... " -ForegroundColor Yellow -NoNewline;
$FOF_CREATEPROGRESSDLG = "&H0G"
$objShell = New-Object -ComObject "Shell.Application"
$objFolder = $objShell.NameSpace("\\$com\C$\$dest")
$objFolder.CopyHere($Source, $FOF_CREATEPROGRESSDLG)
}
catch {
$terror = $_.ErrorDetails.Message
Write-Host "`r [ $com ] TRANSFER FAILED! " -ForegroundColor RED -NoNewline
Write-Host $terror
}
Write-Host "`r [ $com ] "
Wake-Collection -OneShot
}
}
$comsOnline = Wake-Collection
Copy-Files $comsOnline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment