/
GetDailyBingPicture.ps1
35 lines (29 loc) · 1.53 KB
/
GetDailyBingPicture.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#---------------------------------------------
# GetDailyBingPicture.ps1
# Automate and download the daily Bing image
# to the user´s Teams background folder
# Martina Grom, @magrom, atwork.at
# Toni Pohl, @atwork. atwork.at
# see description at
# https://blog.atwork.at/post/Use-the-Daily-Bing-picture-in-Teams-calls
#---------------------------------------------
# Use the Bing.com API.
# The idx parameter determines the day: 0 is the current day, 1 is the previous day, etc. This goes back for max. 7 days.
# The n parameter defines how many pictures you want to load. Usually, n=1 to get the latest picture (of today) only.
# The mkt parameter defines the culture, like en-US, de-DE, etc.
$uri = "https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=en-US"
# Get the picture metadata
$response = Invoke-WebRequest -Method Get -Uri $uri
# Extract the image content
$body = ConvertFrom-Json -InputObject $response.Content
$fileurl = "https://www.bing.com/"+$body.images[0].url
$filename = $body.images[0].startdate+"-"+$body.images[0].title.Replace(" ","-").Replace("?","")+".jpg"
# Download the picture to %APPDATA%\Microsoft\Teams\Backgrounds\Uploads
# $filepath = $env:APPDATA+"\Microsoft\Teams\Backgrounds\Uploads\"+$filename
# or to a local folder...
$filepath = "C:\Users\Toni\OneDrive - atwork gmbh\Pictures\Bing\"+$filename
Invoke-WebRequest -Method Get -Uri $fileurl -OutFile $filepath
# Show the generated picture filepath
$filepath
# Job done.
# You can use that script manually, as daily task, or in your Startup folder. Enjoy!