Powershell Script for iCloud Photos
Trigger downloading photos from iCloud to keep local copies for offline use.
$items = Get-ChildItem 'C:\Users\pacroy\Pictures\iCloud Photos\Photos'
$count = $items.length
$counter = 1
ForEach($item in $items) {
Write-Host -NoNewline "[$counter/$count] $($item.Name) = "
$stopwatch = [system.diagnostics.stopwatch]::StartNew()
$duration = Measure-Command { Get-Content $item.FullName -Encoding byte -TotalCount 1 }
$stopwatch.Stop()
Write-Host "$($duration.Milliseconds)/$([Math]::Round($stopwatch.Elapsed.TotalMilliseconds))"
$counter++
}
Copy iCloud photos into OneDrive Camera Roll according to creation year and month
$items = Get-ChildItem 'C:\Users\nap\Pictures\iCloud Photos\Photos'
$destination = 'C:\Users\nap\OneDrive\Pictures\Camera Roll'
$count = $items.Length
$counter = 1
foreach ($item in $items) {
$year = "{0:d4}" -f $item.CreationTime.Year
$month = "{0:d2}" -f $item.CreationTime.Month
$target = "$destination\$year"
if (-not (Test-Path -LiteralPath $target)) {
New-Item -Path $target -ItemType Directory -ErrorAction Stop | Out-Null
}
$target = "$destination\$year\$month"
if (-not (Test-Path -LiteralPath $target)) {
New-Item -Path $target -ItemType Directory -ErrorAction Stop | Out-Null
}
Write-Host "[$counter/$count] $($item.Name) -> $target"
Copy-Item $item.FullName -Destination "$target\$($item.Name)"
$counter++
}