Sunday, September 4, 2016

Windows Spotlight Wallpapers

If you are anything like me then you were super impressed by the new wallpapers Windows has been pushing out to Windows 10 machines. Well here is a PowerShell function that you can run to find them all, rename them and then sort them into two folders based on the width of the images, some will go into a phone wallpaper folder while the larger images will be saved in the default folder on your desktop.



Function Get-WindowsSpotlightWallpapers{
<#
.Synopsis
   Grabs Windows Spotlight Wallpapers
.DESCRIPTION
   Grabs Microsoft Spotlight Wallpapers and moves them to your desktop, filters out the wallpapers by width and moves the skinny images to a folder for phone wallpapers.
.EXAMPLE
   PS :\> Get-WindowsSpotlightWallpapers
#>
    [CmdletBinding()]
    Param (
            # Path to spotlight files
            [Parameter(Mandatory=$false, ValueFromPipelineByPropertyName=$true,Position=0)]
            $Path = "C:\Users\$env:USERNAME\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets"
          )
            # Moves to the directory the wallpapers are stored in.
            Set-Location -Path $Path
                # copies wallpapers to  folder on you desktop so we don't currupt the originals at all.
                Copy-Item -Path $Path -Recurse -Destination "C:\Users\$env:USERNAME\Desktop\Windows Spotlight Wallpapers\" -Verbose
                    # renames files with .jpeg extention.
                    Get-ChildItem -Path "C:\Users\$env:USERNAME\Desktop\Windows Spotlight Wallpapers\" | Rename-Item -NewName { [io.path]::ChangeExtension($_.name, "jpeg") } -Verbose
                        # deletes files smaller than 25000
                        Get-ChildItem -Path "C:\Users\$env:USERNAME\Desktop\Windows Spotlight Wallpapers\" | Where-Object {$_.Length -lt "25000"} | Remove-Item -Verbose
                           # creates a folder for the phone wallpapers
                            New-Item -Path "C:\Users\$env:USERNAME\Desktop\Windows Spotlight Wallpapers\Windows Spotlight Phone Wallpapers" -ItemType Directory -Verbose | Out-Null
                            # filter files by image width then moves small files to phone wallpaper directory.
                            Function Get-Image{
                                     [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") | Out-Null
                                      $fi=[System.IO.FileInfo]$_          
                                      if( $fi.Exists){
                                                       $img = [System.Drawing.Image]::FromFile($_)
                                                       $img.Clone()
                                                       $img.Dispose()      
                                      } else { Write-Host "File not found: $_" -fore yellow }  
                            }
                            $PhoneWallpapers = Get-ChildItem "C:\Users\$env:USERNAME\Desktop\Windows Spotlight Wallpapers\*.jpeg" -Recurse | % {
                                $image = $_ | Get-Image
                                    New-Object PSObject -Property  @{
                                                                        File = $_.name
                                                                        Fullname = $_.Fullname
                                                                        Height = $image.Height
                                                                        Width = $image.Width
                                    };
                            }
                        # starts 5 second sleep timer
                        Start-Sleep -Seconds 5
                # Goes through wallpapers and moved the smaller width files to the phone wallpaper directory.
                foreach($p in $PhoneWallpapers){
                    if(($p).Width -lt "1081"){
                        Move-Item -Path ($p).fullname -Destination "C:\Users\$env:USERNAME\Desktop\Windows Spotlight Wallpapers\Windows Spotlight Phone Wallpapers\" -Verbose -Force
                        }
                    if(($p).Width -eq "272"){
                        Move-Item -Path ($p).fullname -Destination "C:\Users\$env:USERNAME\Desktop\Windows Spotlight Wallpapers\Windows Spotlight Phone Wallpapers\" -Verbose -Force
                        }
               # starts 5 second sleep timer
               Start-Sleep -Seconds 5
                    if(($p).Width -lt "1081"){
                        Move-Item -Path ($p).fullname -Destination "C:\Users\$env:USERNAME\Desktop\Windows Spotlight Wallpapers\Windows Spotlight Phone Wallpapers\" -ErrorAction SilentlyContinue -Verbose -Force
                        }
                    if(($p).Width -eq "272"){
                        Move-Item -Path ($p).fullname -Destination "C:\Users\$env:USERNAME\Desktop\Windows Spotlight Wallpapers\Windows Spotlight Phone Wallpapers\" -ErrorAction SilentlyContinue -Verbose -Force
                        }
                }
Set-location "C:\Users\$env:USERNAME\Desktop\Windows Spotlight Wallpapers\"
Invoke-Item "C:\Users\$env:USERNAME\Desktop\Windows Spotlight Wallpapers\"
} # end of function.
Get-WindowsSpotLightWallpapers



After running the script I would recommend setting the newly created folder on your desktop as the folder windows uses to grab you wallpapers from.

Simply hit the windows key and start tyoing 'wallpaper' and you should see something that says choose background....

Enjoy!

2 comments:

  1. I do not know if it’s just me or if everyone else encountering issues with your site. It appears as if some of the written text within your content are running off the screen. Can somebody else please comment and let me know if this is happening to them as well? This might be a problem with my browser because I’ve had this happen before. Cheers background blue

    ReplyDelete
  2. cheers for the actual article i have recently been on the lookout with regard to this kind of advice on the net for sum time right now so many thanks blue abstract

    ReplyDelete