Skip to content

Instantly share code, notes, and snippets.

@zplume
Created August 8, 2020 15:07
Show Gist options
  • Select an option

  • Save zplume/884416cb7f9bdbbb99fc67e965537829 to your computer and use it in GitHub Desktop.

Select an option

Save zplume/884416cb7f9bdbbb99fc67e965537829 to your computer and use it in GitHub Desktop.

Revisions

  1. zplume created this gist Aug 8, 2020.
    45 changes: 45 additions & 0 deletions Get-LockScreenImages.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    $imagePath = "$home\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets\*"
    $destinationPath = "$home\OneDrive\Pictures\Lock screen"

    Add-Type -AssemblyName System.Drawing

    # get images from lock screen folder
    $items = Get-ChildItem -Path $imagePath

    foreach($item in $items) {
    $fileName = $item.Name

    # skip small images/icons
    if($item.Length -lt 100000) {
    Write-Host " Skipped " -b Red -f Black -NoNewline
    Write-Host -f White " $($fileName).jpg"
    continue
    }

    # get image dimensions
    $image = New-Object System.Drawing.Bitmap $item.FullName
    $imageWidth = $image.Width
    $imageHeight = $image.Height
    $image.Dispose() # prevent file lock

    # separate images into Landscape/Portrait destination sub-folders
    # note: the script assumes these folders already exist
    if($imageWidth -gt $imageHeight) {
    $newPath = "$destinationPath\Landscape\$($fileName).jpg"
    }
    else {
    $newPath = "$destinationPath\Portrait\$($fileName).jpg"
    }

    # only copy files that haven't
    # already been copied
    if(!(Test-Path $newPath)) {
    Copy-Item -Path $item.FullName -Destination $newPath
    Write-Host -b Green -f Black " Copied " -NoNewline
    }
    else {
    Write-Host -b Yellow -f Black " Exists " -NoNewline
    }

    Write-Host -f White " $($fileName).jpg"
    }