Skip to content

Instantly share code, notes, and snippets.

@mlapierre
Last active August 21, 2016 20:19
Show Gist options
  • Save mlapierre/979d4a47de419dc8e3ab74d2ae58be7f to your computer and use it in GitHub Desktop.
Save mlapierre/979d4a47de419dc8e3ab74d2ae58be7f to your computer and use it in GitHub Desktop.
Copy Windows 10 Spotlight Lock screen images to a user profile directory to be used as wallpaper
Add-Type -AssemblyName System.Drawing
$srcPath = "$env:localappdata\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets"
$destPath = "$env:userprofile\Pictures\Spotlight"
$screenWidth = 1920
# Don't copy a bunch of invalid files and some that I'm not interested in.
$exclude = @(
"4fcb5b1ca951dc6f88d6b6c16a538a934a2024b59f5fff7ae06e3e880b304014",
"0fac3566baf536896c2579bcfc6ee01ab4437809bfb9efa3bb00c2e45da69556",
"163b04cd263d1077940e14b1d18d5def4db28396bef3acc56f5d30957d6d6f19",
"ec62f026c546f06261c649e0bb57b8b25c8dae247371c386d402b11cee30e38a",
"f56a873ab60fd8cdeb294be62701141a8dcc91ac5f6053eeb6298ed925f2c29a",
"9be8da15cc459ceb8560e918c61555d0291f049e0c6e7f1b158f034842b327b8",
"577705f494eae2f1ee016e1c7d7dfaf9cbfe2c008be7a46a65629a4c32e4701a",
"ba06c3629a6e8885cebd767cf63464f25ced63460a442c35c35efa476744c34c",
"cf68fd432353dbc4c5c5070c7b7c321545a9f624eca354f8d4b348b4f84ea935",
"f438151d998cfeaf04fc38670721d82752337959cbb71d7d7bf8d0574ac89974"
)
$count = 0
foreach ($imagePath in Get-ChildItem $srcPath) {
try {
$image = New-Object System.Drawing.Bitmap "$srcPath\$imagePath"
} catch [System.Management.Automation.MethodInvocationException] {
# Ignore the error, it just means the file wasn't a valid image file. There are some in the directory.
}
if ($image -ne $null -And $image.Width -eq $screenWidth `
-And (Test-Path -Path "$destPath\$($imagePath).jpg") -eq $false `
-And -Not ($exclude.Contains($imagePath.Name))) {
Copy-Item "$srcPath\$imagePath" "$destPath\$($imagePath).jpg"
$count++
}
}
"Copied $count new images" | Out-File "$destPath\log.txt"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment