Skip to content

Instantly share code, notes, and snippets.

@heaths
Last active August 2, 2022 01:12
Show Gist options
  • Save heaths/503ff4a28e8519c9089c78d0ce9eb252 to your computer and use it in GitHub Desktop.
Save heaths/503ff4a28e8519c9089c78d0ce9eb252 to your computer and use it in GitHub Desktop.
Copies JPG and PNG images from the Content Delivery Manager.
#Requires -Version 5.1
#Requires -Modules 'Appx'
[CmdletBinding()]
param (
[Parameter(Mandatory=$true, Position=0)]
[string] $Destination,
[Parameter()]
[ValidateNotNullOrEmpty()]
[int] $MinimumSize = 500kb,
[Parameter()]
[switch] $Force
)
$filter = {
$b = Get-Content -LiteralPath $input.PSPath -TotalCount 8 -Encoding Byte
if ($b[0] -eq 0x89 -and $b[1] -eq 0x50 -and $b[2] -eq 0x4e -and $b[3] -eq 0x47 -and `
$b[4] -eq 0x0d -and $b[5] -eq 0x0a -and $b[6] -eq 0x1a -and $b[7] -eq 0x0a) {
$script:extension = 'png'
$true
} elseif ($b[0] -eq 0xff -and $b[1] -eq 0xd8) {
if (($b[2] -eq 0xdd -and $b[3] -eq 0xe0) -or `
($b[2] -eq 0xff -and $b[3] -eq 0xdb) -or `
($b[2] -eq 0xff -and $b[3] -eq 0xe0) -or `
($b[2] -eq 0xff -and $b[3] -eq 0xe1)) {
$script:extension = 'jpg'
$true
}
}
$false
}
$appx = Get-AppxPackage 'Microsoft.Windows.ContentDeliveryManager'
Join-Path $env:LOCALAPPDATA "Packages\$($appx.PackageFamilyName)\LocalState\Assets" `
| Get-ChildItem `
| Where-Object { $_.Length -ge $MinimumSize } `
| Where-Object -FilterScript $filter `
| ForEach-Object -Begin {
$null = New-Item $Destination -ItemType Directory -Force
} -Process {
$destinationFile = Join-Path $Destination "$($_.Name).$extension"
$_ | Copy-Item -Destination $destinationFile -Force:$Force -PassThru
}
<#
.SYNOPSIS
Copies JPG and PNG images from the Content Delivery Manager.
.DESCRIPTION
Copies all detected JPG and PNG images from the Windows Content Delivery Manager.
Detection is based on the $MinimumSize and magic numbers (first few bytes).
.PARAMETER Destination
The destination folder to where images are copied.
.PARAMETER MinimumSize
The minimum file size of files to scan.
.PARAMETER Force
Overwrite files when copying.
.OUTPUTS
System.IO.FileInfo
#>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment