Advertisement
easternnl

Save Windows 10 background images

Dec 18th, 2015
569
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Copy the nice Windows 10 background images to a folder where you can keep them.
  2.  
  3. # -----------------------------------------------------------------------------
  4. # Script: Get-FileMetaDataReturnObject.ps1
  5. # Author: ed wilson, msft
  6. # Date: 01/24/2014 12:30:18
  7. # Keywords: Metadata, Storage, Files
  8. # comments: Uses the Shell.APplication object to get file metadata
  9. # Gets all the metadata and returns a custom PSObject
  10. # it is a bit slow right now, because I need to check all 266 fields
  11. # for each file, and then create a custom object and emit it.
  12. # If used, use a variable to store the returned objects before attempting
  13. # to do any sorting, filtering, and formatting of the output.
  14. # To do a recursive lookup of all metadata on all files, use this type
  15. # of syntax to call the function:
  16. # Get-FileMetaData -folder (gci e:\music -Recurse -Directory).FullName
  17. # note: this MUST point to a folder, and not to a file.
  18. # -----------------------------------------------------------------------------
  19. Function Get-FileMetaData
  20. {
  21.   <#
  22.    .Synopsis
  23.     This function gets file metadata and returns it as a custom PS Object  
  24.    .Description
  25.     This function gets file metadata using the Shell.Application object and
  26.     returns a custom PSObject object that can be sorted, filtered or otherwise
  27.     manipulated.
  28.    .Example
  29.     Get-FileMetaData -folder "e:\music"
  30.     Gets file metadata for all files in the e:\music directory
  31.    .Example
  32.     Get-FileMetaData -folder (gci e:\music -Recurse -Directory).FullName
  33.     This example uses the Get-ChildItem cmdlet to do a recursive lookup of  
  34.     all directories in the e:\music folder and then it goes through and gets
  35.     all of the file metada for all the files in the directories and in the  
  36.     subdirectories.  
  37.    .Example
  38.     Get-FileMetaData -folder "c:\fso","E:\music\Big Boi"
  39.     Gets file metadata from files in both the c:\fso directory and the
  40.     e:\music\big boi directory.
  41.    .Example
  42.     $meta = Get-FileMetaData -folder "E:\music"
  43.     This example gets file metadata from all files in the root of the
  44.     e:\music directory and stores the returned custom objects in a $meta  
  45.     variable for later processing and manipulation.
  46.    .Parameter Folder
  47.     The folder that is parsed for files  
  48.    .Notes
  49.     NAME:  Get-FileMetaData
  50.     AUTHOR: ed wilson, msft
  51.     LASTEDIT: 01/24/2014 14:08:24
  52.     KEYWORDS: Storage, Files, Metadata
  53.     HSG: HSG-2-5-14
  54.    .Link
  55.      Http://www.ScriptingGuys.com
  56.  #Requires -Version 2.0
  57.  #>
  58.  Param([string[]]$folder)
  59.  foreach($sFolder in $folder)
  60.   {
  61.    $a = 0
  62.    $objShell = New-Object -ComObject Shell.Application
  63.    $objFolder = $objShell.namespace($sFolder)
  64.  
  65.    foreach ($File in $objFolder.items())
  66.     {  
  67.      $FileMetaData = New-Object PSOBJECT
  68.       for ($a ; $a  -le 266; $a++)
  69.        {  
  70.          if($objFolder.getDetailsOf($File, $a))
  71.            {
  72.              $hash += @{$($objFolder.getDetailsOf($objFolder.items, $a))  =
  73.                    $($objFolder.getDetailsOf($File, $a)) }
  74.             $FileMetaData | Add-Member $hash
  75.             $hash.clear()  
  76.            } #end if
  77.        } #end for  
  78.      $a=0
  79.      $FileMetaData
  80.     } #end foreach $file
  81.   } #end foreach $sfolder
  82. } #end Get-FileMetaData
  83.  
  84. $null = mkdir "$env:temp\Background" -ErrorAction SilentlyContinue -Force
  85. $null = mkdir "c:\Users\$($env:USERNAME)\Pictures\Background" -ErrorAction SilentlyContinue -Force
  86.  
  87. # List the files in the folder where Windows download all the nice pictures
  88. $files = ls "C:\Users\$($env:username)\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets"
  89.  
  90. # Create a copy with the .JPG extension to the %temp%\Background folder
  91. foreach ($file in $files)
  92. {
  93.     copy-item $file.fullname "$($env:temp)\Background\$($file.basename).jpg"
  94.     #write-host $file.fullname "$($env:temp)\Background\$($file.basename).jpg"
  95. }
  96.  
  97. # process the properties to
  98. $picMetadatas = Get-FileMetaData -folder $env:temp\Background
  99.  
  100. foreach ($picMetadata in $picMetadatas)
  101. {
  102.     # check if the width is longer than 1500, if yes copy to the background folder ;-)
  103.     if($picMetadata.Width -eq "1920 pixels")
  104.     {
  105.         Write-Host "Adding $picMetadata.path"
  106.        
  107.         copy-item $picMetadata.path "c:\Users\$($env:USERNAME)\Pictures\Background" -Force
  108.     }
  109.  
  110. }
  111.  
  112. # delete the folder
  113. #rmdir "$env:temp\Background" -Force
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement