unable to change backgroud on devices via intune

Bronze Contributor

Hi all,

 

I am using: 

 $RegKeyPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\PersonalizationCSP"

$DesktopPath = "DesktopImagePath"

$DesktopStatus = "DesktopImageStatus"

$DesktopUrl = "DesktopImageUrl"

$StatusValue = "1"

$url = "openlocationlinkhere.jpeg"

$DesktopImageValue = "C:\MDM\getinvolved.jpg"

$directory = "C:\MDM\"

If ((Test-Path -Path $directory) -eq $false)

{

New-Item -Path $directory -ItemType directory

}

 

$wc = New-Object System.Net.WebClient

$wc.DownloadFile($url, $DesktopImageValue)

if (!(Test-Path $RegKeyPath))

{

Write-Host "Creating registry path $($RegKeyPath)."

New-Item -Path $RegKeyPath -Force | Out-Null

}

New-ItemProperty -Path $RegKeyPath -Name $DesktopStatus -Value $Statusvalue -PropertyType DWORD -Force | Out-Null

New-ItemProperty -Path $RegKeyPath -Name $DesktopPath -Value $DesktopImageValue -PropertyType STRING -Force | Out-Null

New-ItemProperty -Path $RegKeyPath -Name $DesktopUrl -Value $DesktopImageValue -PropertyType STRING -Force | Out-Null 

 

But when I use this locally on a test machine before deploying it doesnt work and errors out / powershell window closes before I can check the error. 

 

Is this the best way of deploying backgrounds? or is there a more reliable way

6 Replies
I've just this one in the past, bit more work but you can set the correct wallpaper for each type of screen

https://oliverkieselbach.com/2021/02/23/set-preference-for-a-suitable-wallpaper-with-intune/
Hi,

Normally this script works... but we don't have any background information of the "test device"
Of course if you have the properlicensing you can set it up in Intune
https://365tips.be/en/setting-the-background-and-lock-screen-in-microsoft-endpoint-manager/

What happens when you deploy it intune? What happens when you open a powershell session first and copy paste the powershell script in parts... so you would get your error

Hi both @Rudy_Ooms_MVP @Harm_Veenstra 

 

So seems like the script works but for some odd reason it doesn't like the URL I used for the image. this image opens fine when entering on a incognito browser

Screenshot 2022-02-05 at 2.58.13 PM.png

 

So I have got it working a long way but it works even though the script fails.on intune.

 

What I have done is push the image out via win32 app to go into the location c:\MDM then the script does the rest. Even though this works I think the script is failing due to it having code in it which I no longer need due to deploying the image through a win32 app.

 

Any ideas which bit i need to remove? so it says successful on intune rather than failed for the script

If it does work, the wallpaper is actually set on the machine, then it could be that the script exits with a bad error code. You could try ending the script with "exit 0" ?
You could try to convert it to a proactive remediations so you could get some "feedback" of what happened on the client. And I agree with harm, Exit codes are quit important :)
https://call4cloud.nl/2021/05/imecache-attack-of-the-cleaner/#part5

@AB21805 

you're using the DownloadFile method of the System.Net.WebClient object. How about you just put that code in a script, enable debugging and review the $error variable for more insight?

 

#image URL
$URL = "https://image-url"
#image path
$imagePath = "c:\path-to-save-image"
$itr = 1 
while($itr -le 5)
{
write-host "Try number:$itr" -ForegroundColor green
try
{
Write-host "Getting image from $URL"
$webclient = new-object System.Net.WebClient
$webclient.DownloadFile($URL, $imagePath)
write-host "webClient transfer complete, breaking loop" -ForegroundColor green
break
}
catch
{
write-host "$($error[0].Exception.ToString())"
$itr += 1

if($itr -gt 5)
{
write-host "$($itr-1) failed tries exiting script" -foregroundColor red
exit 0
}
}
} #end while