Skip to content

Downloads Bing background images in a defined resolution (a Windows PowerShell script).

License

Notifications You must be signed in to change notification settings

auberginehill/get-bing-background-images

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Get-BingBackgroundImages.ps1

OS: Windows
Type: A Windows PowerShell script
Language: Windows PowerShell
Description:

Get-BingBackgroundImages downloads a Bing XML-file (bing.xml) from Bing http://www.bing.com/HPImageArchive.aspx?format=xml&idx=[Index]&n=[NumberOfImages]&mkt=[Market] containing info about the queried daily background images, which were recently featured on the Bing search engine homepage as a daily changing background image. Microsoft's Bing search engine is famous for using hand-picked beautiful imagery on their main landing page. The daily background images regularly depict stunning landmarks, inspiring nature shots and high quality pictures of people and cultures from around the world.

After determining the save locations, which are set with -Destination and -Subfolder parameters, Get-BingBackgroundImages compares the filenames found in the destination folders to the filenames listed in the XML-file (bing.xml) and tries to determine, whether downloading an image is actually needed or not. Get-BingBackgroundImages tries to avoid any unnecessary downloading and overwriting of the existing files.

By using the Bing API with AJAX calls it seems to be possible to retrieve up to 14 days old pictures and up to 8 images at a time. To retrieve all currently available Bing background images in the default 1920x1080 resolution along with the 1080x1920 portrait variants as well from the default Bing market (en-US) with Get-BingBackgroundImages and to create/update a log file (bing_log.csv), please use two separate commands launching Get-BingBackgroundImages:

    .\Get-BingBackgroundImages.ps1 -Index 0 -NumberOfImages 7 -Log -IncludePortrait
    .\Get-BingBackgroundImages.ps1 -Index 7 -NumberOfImages 8 -Log -IncludePortrait

Please note that Get-BingBackgroundImages proceeds towards the history, when handling multiple images. Please also note that if any of the individual parameter values include space characters, the individual value should be enclosed in quotation marks (single or double) so that PowerShell can interpret the command correctly. This script is based on Jeffrey's script "Get-BingImage.ps1".

Homepage: https://github.com/auberginehill/get-bing-background-images
Short URL: http://tinyurl.com/jjnuvqr
Version: 1.0
Sources: Emojis: Emoji Table
Jeffrey: Get-BingImage.ps1
clayman2: Disk Space (or one of the archive.org versions)
ps1: Test Internet connection (or one of the archive.org versions)
Tobias Weltner: PowerTips Monthly vol 10 March 2014, Read raw web page content (or one of the archive.org versions)
Downloads: For instance Get-BingBackgroundImages.ps1. Or everything as a .zip-file.

Screenshot

screenshot

Parameters

📐
  • Parameter -Destination

    with aliases -Path, -Output and -OutputFolder. Specifies the primary folder, where the acquired new Bing background images are to be saved, and defines the default location to be used with the -Log parameter (bing_log.csv), and also sets the parent directory for the -Subfolder parameter. The default save location for the horizontal (landscape) Bing background images is "$env:USERPROFILE\Pictures\Wallpapers\Bing", which will be used, if no value for the -Destination parameter is defined in the command launching Get-BingBackgroundImages. For best results in iterative usage of this script, the default value should remain constant and be set according to the prevailing conditions (at line 13). The value for the -Destination parameter should be a valid file system path pointing to a directory (a full path of a folder such as C:\Users\Dropbox\). Furthermore, if the path includes space characters, please enclose the path in quotation marks (single or double).

  • Parameter -Market

    Sets the Bing market, from where the images are downloaded. The valid values are: en-US, zh-CN, ja-JP, en-AU, en-UK, de-DE, en-NZ and en-CA. If no value for the -Market parameter is defined in the command launching Get-BingBackgroundImages, the default value "en-US" will be used.

  • Parameter -Index

    Sets the start date, from which point towards the history should the images be retrieved. 0 denominates the current day, 1 denominates yesterday, 2 denominates the day before yesterday etc. It should be noted that Get-BingBackgroundImages always counts "backwads" (towards the history), when retrieving multiple Bing background images, and that by default, Get-BingBackgroundImages starts to count the images from the current day.

  • Parameter -NumberOfImages

    with aliases -Number, -Amount and -Images. Sets the number of images to return. n = 1 would return only one, n = 2 would return two, and so on up to eight. By default Get-BingBackgroundImages retrieves one image. It should also be noted that Get-BingBackgroundImages always counts "backwads" (towards the history), when retrieving Bing background images.

  • Parameter -Resolution

    Sets the native resolution of the retrieved images. Only some resolutions are natively supported by Bing, and if the resolution is not supported, this script will most likely fail. Get-BingBackgroundImages doesn't convert images, when the -Resolution parameter is defined – it only tries to retrieve already available images in the specified resolution from Bing. The format is [width]x[height] without the opening or closing brackets. Valid -Resolution parameter values include, for instance:

      1366x768
      1920x1080
      1920×1200
      1080x1920

  • Parameter -Subfolder

    with aliases -SubfolderForThePortraitPictures, -SubfolderForTheVerticalPictures and -SubfolderName. Specifies the name of the subfolder, where the new portrait pictures are to be saved. The value for the -Subfolder parameter should be a plain directory name (omitting the path and the parent directories). The default value is "Vertical", which is used if no value for the -Subfolder parameter is defined in the command launching Get-BingBackgroundImages. For best results in iterative usage of Get-BingBackgroundImages, the default value should remain constant and be set according to the prevailing conditions at line 23. Furthermore, if the directory name includes space characters, please enclose the directory name in quotation marks (single or double).

  • Parameter -Log

    If the -Log parameter is added to the command launching Get-BingBackgroundImages, a log file creation/updating procedure is initiated, if new images are downloaded. The log file (bing_log.csv) is created or updated at the path defined with the -Destination parameter. If the CSV log file seems to already exist, new data will be appended to the end of that file. The log file contains over 30 image metadata properties. For instance, the 'Custom URL' column lists a link to the homepage of the picture at http://www.bing.com/gallery containing additional information about the image and a detailed description.

    A rather peculiar append procedure is used instead of the native -Append parameter of the Export-Csv cmdlet for ensuring, that the CSV file will not contain any additional quotation marks(, which might mess up the layout in some scenarios).

  • Parameter -IncludePortrait

    with an alias -Include. If the -IncludePortrait parameter is used in the command launching Get-BingBackgroundImages, and if the primary resolution set with the -Resolution parameter seems to indicate that a horizontal (landscape) image is being aquired, Get-BingBackgroundImages tries to download a particular horizontal (landscape) image in the portrait format as well (with swapped width and height values) along with the "normally" downloaded horizontal (landscape) image. The landscape images are placed in the folder set with the -Destination parameter, and the portrait pictures are placed to a subfolder inside the -Destination main folder. The default name of the subfolder ("Vertical") may be changed with the -Subfolder parameter.

Outputs

➡️
  • Displays a summary of the actions in console. Writes the Bing XML-file (bing.xml) to $env:temp. Displays the downloaded files in a pop-up window (Out-GridView). Saves the retrieved images in locations defined with the -Destination and -Subfolder parameters. Additionally, if the -Log parameter is included in the command launching Get-BingBackgroundImages, a log file creation updating procedure is initiated at the path defined with the -Destination variable.

      Default values (the log file (bing_log.csv) creation/updating procedure only occurs, if the -Log parameter is used and new files are found):

      Path Type
      "$env:temp\bing.xml" XML-file
      "$env:USERPROFILE\Pictures\Wallpapers\Bing" The folder for landscape wallpapers
      "$env:USERPROFILE\Pictures\Wallpapers\Bing\bing_log.csv" CSV-file
      "$env:USERPROFILE\Pictures\Wallpapers\Bing\Vertical" The folder for portrait pictures

Notes

⚠️
  • Please note that all the parameters can be used in one get Bing background images command and that each of the parameters can be "tab completed" before typing them fully (by pressing the [tab] key).

  • To see the Bing Homepage Gallery, which showcases images featured on the U.S. Bing homepage during the past 5 years, please visit http://www.bing.com/gallery/. For a mobile alternative on Windows 10 Mobile, Windows Phone 8.1 or Windows Phone 8, please check out the Picture of the Day -app at the Microsoft Store, which downloads the pictures in 1080p directly to the Picture Hub.
  • Please note that the Bing XML-file (bing.xml) is saved to $env:temp directory, and that the destination folders for images are end-user settable in each get Bing background images command with the -Destination and -Subfolder parameters. The $env:temp variable points to the current temp folder. The default value of the $env:temp variable is C:\Users\<username>\AppData\Local\Temp (i.e. each user account has their own separate temp folder at path %USERPROFILE%\AppData\Local\Temp). To see the current temp path, for instance a command

    [System.IO.Path]::GetTempPath()

    may be used at the PowerShell prompt window [PS>]. To change the temp folder for instance to C:\Temp, please, for example, follow the instructions at Temporary Files Folder - Change Location in Windows, which in essence are something along the lines:
    1. Right click Computer icon and select Properties (or select Start → Control Panel → System. On Windows 10 this instance may also be found by right clicking Start and selecting Control Panel → System... or by pressing [Win-key] + X and selecting Control Panel → System). On the window with basic information about the computer...
    2. Click on Advanced system settings on the left panel and select Advanced tab on the "System Properties" pop-up window.
    3. Click on the button near the bottom labeled Environment Variables.
    4. In the topmost section, which lists the User variables, both TMP and TEMP may be seen. Each different login account is assigned its own temporary locations. These values can be changed by double clicking a value or by highlighting a value and selecting Edit. The specified path will be used by Windows and many other programs for temporary files. It's advisable to set the same value (a directory path) for both TMP and TEMP.
    5. Any running programs need to be restarted for the new values to take effect. In fact, probably Windows itself needs to be restarted for it to begin using the new values for its own temporary files.

Examples

📖 To open this code in Windows PowerShell, for instance:

  1. ./Get-BingBackgroundImages.ps1
    Runs the script. Please notice to insert ./ or .\ before the script name. Tries to download the Bing background image currently featured on Bing search engine homepage, since no values for the -NumberOfImages or -Index parameters were defined. Saves the downloaded Bing XML-file (bing.xml) to $env:temp. Queries the default -Destination folder "$env:USERPROFILE\Pictures\Wallpapers\Bing" for existing files and compares the filenames found in that folder to the filenames listed in the Bing XML-file (bing.xml), and downloads all the files listed in the Bing XML-file (bing.xml), which don't exist at the -Destination folder. Uses the default market ("en-US") and the default resolution ("1920x1080") for the type of image to download and saves the image to the default -Destination folder ("$env:USERPROFILE\Pictures\Wallpapers\Bing"). A pop-up window listing the new files will open, if new files were downloaded.
  2. help ./Get-BingBackgroundImages -Full
    Displays the help file.
  3. ./Get-BingBackgroundImages.ps1 -Market en-UK -Index 0 -NumberOfImages 7 -Resolution 1920x1080 -Log -IncludePortrait
    Tries to download seven latest background images from Bing (today's picture and six previous pictures) in the landscape and portrait formats. If some "root" files listed in the Bing XML-file (bing.xml) seem not to exist at the default -Destination folder in 1920x1080 resolution or at the default -Subfolder ("Vertical") in 1080x1920 resolution, retrieves those images from the en-UK Bing market. If new images were obtained, writes or updates a log file (bing_log.csv) at the default -Destination folder, and a pop-up window listing the new files will open.
  4. ./Get-BingBackgroundImages.ps1 -Index 7 -NumberOfImages 8 -Destination C:\Users\Dropbox\ -Subfolder Mobile -IncludePortrait
    Tries to download eight pictures from Bing between the dates two weeks ago and one week ago (including the start and end dates) in the landscape and portrait formats. The actual download procedure is done "backwards" i.e. the newest photo is downloaded first. If some files listed in the Bing XML-file (bing.xml) seem not to exist at the -Destination folder ("C:\Users\Dropbox\") in the default (1920x1080) resolution or at the -Subfolder ("Mobile") in 1080x1920 resolution, retrieves those images from the default en-US Bing market, and a pop-up window listing the new files will open. Since the path or the subfolder name doesn't contain any space characters, they don't need to be enveloped with quotation marks.
  5. Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine
    This command is altering the Windows PowerShell rights to enable script execution in the default (LocalMachine) scope, and defines the conditions under which Windows PowerShell loads configuration files and runs scripts in general. In Windows Vista and later versions of Windows, for running commands that change the execution policy of the LocalMachine scope, Windows PowerShell has to be run with elevated rights (Run as Administrator). The default policy of the default (LocalMachine) scope is "Restricted", and a command "Set-ExecutionPolicy Restricted" will "undo" the changes made with the original example above (had the policy not been changed before...). Execution policies for the local computer (LocalMachine) and for the current user (CurrentUser) are stored in the registry (at for instance the HKLM:\Software\Policies\Microsoft\Windows\PowerShell\ExecutionPolicy key), and remain effective until they are changed again. The execution policy for a particular session (Process) is stored only in memory, and is discarded when the session is closed.

    Parameters:

      Restricted Does not load configuration files or run scripts, but permits individual commands. Restricted is the default execution policy.
      AllSigned Scripts can run. Requires that all scripts and configuration files be signed by a trusted publisher, including the scripts that have been written on the local computer. Risks running signed, but malicious, scripts.
      RemoteSigned Requires a digital signature from a trusted publisher on scripts and configuration files that are downloaded from the Internet (including e-mail and instant messaging programs). Does not require digital signatures on scripts that have been written on the local computer. Permits running unsigned scripts that are downloaded from the Internet, if the scripts are unblocked by using the Unblock-File cmdlet. Risks running unsigned scripts from sources other than the Internet and signed, but malicious, scripts.
      Unrestricted Loads all configuration files and runs all scripts. Warns the user before running scripts and configuration files that are downloaded from the Internet. Not only risks, but actually permits, eventually, running any unsigned scripts from any source. Risks running malicious scripts.
      Bypass Nothing is blocked and there are no warnings or prompts. Not only risks, but actually permits running any unsigned scripts from any source. Risks running malicious scripts.
      Undefined Removes the currently assigned execution policy from the current scope. If the execution policy in all scopes is set to Undefined, the effective execution policy is Restricted, which is the default execution policy. This parameter will not alter or remove the ("master") execution policy that is set with a Group Policy setting.
      Notes:
      • Please note that the Group Policy setting "Turn on Script Execution" overrides the execution policies set in Windows PowerShell in all scopes. To find this ("master") setting, please, for example, open the Local Group Policy Editor (gpedit.msc) and navigate to Computer Configuration → Administrative Templates → Windows Components → Windows PowerShell.
      • The Local Group Policy Editor (gpedit.msc) is not available in any Home or Starter edition of Windows.
        1. Group Policy Setting "Turn on Script Execution" PowerShell Equivalent (concerning all scopes)
          Not configured No effect, the default value of this setting
          Disabled Restricted
          Enabled – Allow only signed scripts AllSigned
          Enabled – Allow local scripts and remote signed scripts RemoteSigned
          Enabled – Allow all scripts Unrestricted

    For more information, please type "Get-ExecutionPolicy -List", "help Set-ExecutionPolicy -Full", "help about_Execution_Policies" or visit Set-ExecutionPolicy or about_Execution_Policies.

  6. New-Item -ItemType File -Path C:\Temp\Get-BingBackgroundImages.ps1
    Creates an empty ps1-file to the C:\Temp directory. The New-Item cmdlet has an inherent -NoClobber mode built into it, so that the procedure will halt, if overwriting (replacing the contents) of an existing file is about to happen. Overwriting a file with the New-Item cmdlet requires using the Force. If the path name and/or the filename includes space characters, please enclose the whole -Path parameter value in quotation marks (single or double):

      New-Item -ItemType File -Path "C:\Folder Name\Get-BingBackgroundImages.ps1"

    For more information, please type "help New-Item -Full".

Contributing

contributing Bugs: Bugs can be reported by creating a new issue.
Feature Requests: Feature request can be submitted by creating a new issue.
Editing Source Files: New features, fixes and other potential changes can be discussed in further detail by opening a pull request.

www

🌐 Script Homepage
Jeffrey: Get-BingImage.ps1
clayman2: Disk Space (or one of the archive.org versions)
ps1: Test Internet connection (or one of the archive.org versions)
Tobias Weltner: PowerTips Monthly vol 10 March 2014, Read raw web page content (or one of the archive.org versions)
Remove Unwanted Quotation Marks from CSV Files by Using PowerShell
Uri Class
Powershellv2 - remove last x characters from a string
Append files using export-csv for PowerShell 2
PowerShell script to download Bing's daily image as a wallpaper
Is there a way to get Bing's photo of the day?
Bing Image Download
ASCII Art: http://www.figlet.org/ and ASCII Art Text Generator

Related scripts

www Disable-Defrag
Emoji Table
Firefox Customization Files
Get-AsciiTable
Get-BatteryInfo
Get-ComputerInfo
Get-CultureTables
Get-DirectorySize
Get-HashValue
Get-InstalledPrograms
Get-InstalledWindowsUpdates
Get-PowerShellAliasesTable
Get-PowerShellSpecialFolders
Get-RAMInfo
Get-TimeDifference
Get-TimeZoneTable
Get-UnusedDriveLetters
Get-Windows10LockScreenWallpapers
Java-Update
Remove-DuplicateFiles
Remove-EmptyFolders
Remove-EmptyFoldersLite
Rename-Files
Rock-Paper-Scissors
Toss-a-Coin
Unzip-Silently
Update-AdobeFlashPlayer
Update-MozillaFirefox

About

Downloads Bing background images in a defined resolution (a Windows PowerShell script).

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published