Tech Community Live: Endpoint Manager edition
Jul 21 2022, 08:00 AM - 12:00 PM (PDT)

unable to change backgroud on devices via intune

%3CLINGO-SUB%20id%3D%22lingo-sub-3117946%22%20slang%3D%22en-US%22%3Eunable%20to%20change%20backgroud%20on%20devices%20via%20intune%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3117946%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20all%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20using%3A%26nbsp%3B%3C%2FP%3E%3CP%20class%3D%22%22%3E%3CSPAN%20class%3D%22%22%3E%3CSPAN%20class%3D%22%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FSPAN%3E%3CSPAN%20class%3D%22%22%3E%24RegKeyPath%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22%22%3E%3D%3C%2FSPAN%3E%20%22HKLM%3A%5CSOFTWARE%5CMicrosoft%5CWindows%5CCurrentVersion%5CPersonalizationCSP%22%3C%2FP%3E%3CP%20class%3D%22%22%3E%3CSPAN%20class%3D%22%22%3E%24DesktopPath%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22%22%3E%3D%3C%2FSPAN%3E%20%22DesktopImagePath%22%3C%2FP%3E%3CP%20class%3D%22%22%3E%3CSPAN%20class%3D%22%22%3E%24DesktopStatus%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22%22%3E%3D%3C%2FSPAN%3E%20%22DesktopImageStatus%22%3C%2FP%3E%3CP%20class%3D%22%22%3E%3CSPAN%20class%3D%22%22%3E%24DesktopUrl%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22%22%3E%3D%3C%2FSPAN%3E%20%22DesktopImageUrl%22%3C%2FP%3E%3CP%20class%3D%22%22%3E%24StatusValue%20%3CSPAN%20class%3D%22%22%3E%3D%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22%22%3E%221%22%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22%22%3E%3CSPAN%20class%3D%22%22%3E%24url%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22%22%3E%3D%3C%2FSPAN%3E%20%22openlocationlinkhere.jpeg%22%3C%2FP%3E%3CP%20class%3D%22%22%3E%3CSPAN%20class%3D%22%22%3E%24DesktopImageValue%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22%22%3E%3D%3C%2FSPAN%3E%20%22C%3A%5CMDM%5Cgetinvolved.jpg%22%3C%2FP%3E%3CP%20class%3D%22%22%3E%24directory%20%3CSPAN%20class%3D%22%22%3E%3D%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22%22%3E%22C%3A%5CMDM%5C%22%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22%22%3E%3CSPAN%20class%3D%22%22%3EIf%3C%2FSPAN%3E%3CSPAN%20class%3D%22%22%3E%20((%3C%2FSPAN%3E%3CSPAN%20class%3D%22%22%3ETest-Path%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22%22%3E-Path%3C%2FSPAN%3E%20%24directory%3CSPAN%20class%3D%22%22%3E)%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22%22%3E-eq%3C%2FSPAN%3E%20%24false%3CSPAN%20class%3D%22%22%3E)%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22%22%3E%7B%3C%2FP%3E%3CP%20class%3D%22%22%3E%3CSPAN%20class%3D%22%22%3ENew-Item%3C%2FSPAN%3E%20-Path%20%3CSPAN%20class%3D%22%22%3E%24directory%3C%2FSPAN%3E%20-ItemType%20%3CSPAN%20class%3D%22%22%3Edirectory%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22%22%3E%7D%3C%2FP%3E%3CP%20class%3D%22%22%3E%26nbsp%3B%3C%2FP%3E%3CP%20class%3D%22%22%3E%3CSPAN%20class%3D%22%22%3E%24wc%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22%22%3E%3D%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22%22%3ENew-Object%3C%2FSPAN%3E%20System.Net.WebClient%3C%2FP%3E%3CP%20class%3D%22%22%3E%24wc%3CSPAN%20class%3D%22%22%3E.%3C%2FSPAN%3E%3CSPAN%20class%3D%22%22%3EDownloadFile(%3C%2FSPAN%3E%24url%3CSPAN%20class%3D%22%22%3E%2C%3C%2FSPAN%3E%20%24DesktopImageValue%3CSPAN%20class%3D%22%22%3E)%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22%22%3E%3CSPAN%20class%3D%22%22%3Eif%3C%2FSPAN%3E%3CSPAN%20class%3D%22%22%3E%20(%3C%2FSPAN%3E%3CSPAN%20class%3D%22%22%3E!%3C%2FSPAN%3E%3CSPAN%20class%3D%22%22%3E(%3C%2FSPAN%3E%3CSPAN%20class%3D%22%22%3ETest-Path%3C%2FSPAN%3E%20%24RegKeyPath%3CSPAN%20class%3D%22%22%3E))%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22%22%3E%7B%3C%2FP%3E%3CP%20class%3D%22%22%3E%3CSPAN%20class%3D%22%22%3EWrite-Host%3C%2FSPAN%3E%20%22Creating%20registry%20path%20%3CSPAN%20class%3D%22%22%3E%24(%3C%2FSPAN%3E%3CSPAN%20class%3D%22%22%3E%24RegKeyPath%3C%2FSPAN%3E%3CSPAN%20class%3D%22%22%3E)%3C%2FSPAN%3E.%22%3C%2FP%3E%3CP%20class%3D%22%22%3ENew-Item%20%3CSPAN%20class%3D%22%22%3E-Path%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22%22%3E%24RegKeyPath%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22%22%3E-Force%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22%22%3E%7C%3C%2FSPAN%3E%20Out-Null%3C%2FP%3E%3CP%20class%3D%22%22%3E%7D%3C%2FP%3E%3CP%20class%3D%22%22%3E%3CSPAN%20class%3D%22%22%3ENew-ItemProperty%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22%22%3E-Path%3C%2FSPAN%3E%20%24RegKeyPath%20%3CSPAN%20class%3D%22%22%3E-Name%3C%2FSPAN%3E%20%24DesktopStatus%20%3CSPAN%20class%3D%22%22%3E-Value%3C%2FSPAN%3E%20%24Statusvalue%20%3CSPAN%20class%3D%22%22%3E-PropertyType%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22%22%3EDWORD%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22%22%3E-Force%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22%22%3E%7C%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22%22%3EOut-Null%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22%22%3E%3CSPAN%20class%3D%22%22%3ENew-ItemProperty%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22%22%3E-Path%3C%2FSPAN%3E%20%24RegKeyPath%20%3CSPAN%20class%3D%22%22%3E-Name%3C%2FSPAN%3E%20%24DesktopPath%20%3CSPAN%20class%3D%22%22%3E-Value%3C%2FSPAN%3E%20%24DesktopImageValue%20%3CSPAN%20class%3D%22%22%3E-PropertyType%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22%22%3ESTRING%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22%22%3E-Force%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22%22%3E%7C%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22%22%3EOut-Null%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22%22%3E%3CSPAN%20class%3D%22%22%3ENew-ItemProperty%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22%22%3E-Path%3C%2FSPAN%3E%20%24RegKeyPath%20%3CSPAN%20class%3D%22%22%3E-Name%3C%2FSPAN%3E%20%24DesktopUrl%20%3CSPAN%20class%3D%22%22%3E-Value%3C%2FSPAN%3E%20%24DesktopImageValue%20%3CSPAN%20class%3D%22%22%3E-PropertyType%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22%22%3ESTRING%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22%22%3E-Force%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22%22%3E%7C%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22%22%3EOut-Null%3CSPAN%20class%3D%22%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22%22%3E%26nbsp%3B%3C%2FP%3E%3CP%20class%3D%22%22%3E%3CSPAN%20class%3D%22%22%3E%3CSPAN%20class%3D%22%22%3EBut%20when%20I%20use%20this%20locally%20on%20a%20test%20machine%20before%20deploying%20it%20doesnt%20work%20and%20errors%20out%20%2F%20powershell%20window%20closes%20before%20I%20can%20check%20the%20error.%26nbsp%3B%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22%22%3E%26nbsp%3B%3C%2FP%3E%3CP%20class%3D%22%22%3E%3CSPAN%20class%3D%22%22%3E%3CSPAN%20class%3D%22%22%3EIs%20this%20the%20best%20way%20of%20deploying%20backgrounds%3F%20or%20is%20there%20a%20more%20reliable%20way%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3117946%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EConditional%20Access%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EGraph%20API%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EIntune%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMobile%20Application%20Management%20(MAM)%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMobile%20Device%20Management%20(MDM)%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESoftware%20Management%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3119545%22%20slang%3D%22en-US%22%3ERe%3A%20unable%20to%20change%20backgroud%20on%20devices%20via%20intune%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3119545%22%20slang%3D%22en-US%22%3EI've%20just%20this%20one%20in%20the%20past%2C%20bit%20more%20work%20but%20you%20can%20set%20the%20correct%20wallpaper%20for%20each%20type%20of%20screen%3CBR%20%2F%3E%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Foliverkieselbach.com%2F2021%2F02%2F23%2Fset-preference-for-a-suitable-wallpaper-with-intune%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Foliverkieselbach.com%2F2021%2F02%2F23%2Fset-preference-for-a-suitable-wallpaper-with-intune%2F%3C%2FA%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3120154%22%20slang%3D%22en-US%22%3ERe%3A%20unable%20to%20change%20backgroud%20on%20devices%20via%20intune%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3120154%22%20slang%3D%22en-US%22%3EHi%2C%3CBR%20%2F%3E%3CBR%20%2F%3ENormally%20this%20script%20works...%20but%20we%20don't%20have%20any%20background%20information%20of%20the%20%22test%20device%22%3CBR%20%2F%3EOf%20course%20if%20you%20have%20the%20properlicensing%20you%20can%20set%20it%20up%20in%20Intune%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2F365tips.be%2Fen%2Fsetting-the-background-and-lock-screen-in-microsoft-endpoint-manager%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2F365tips.be%2Fen%2Fsetting-the-background-and-lock-screen-in-microsoft-endpoint-manager%2F%3C%2FA%3E%3CBR%20%2F%3E%3CBR%20%2F%3EWhat%20happens%20when%20you%20deploy%20it%20intune%3F%20What%20happens%20when%20you%20open%20a%20powershell%20session%20first%20and%20copy%20paste%20the%20powershell%20script%20in%20parts...%20so%20you%20would%20get%20your%20error%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3120673%22%20slang%3D%22en-US%22%3ERe%3A%20unable%20to%20change%20backgroud%20on%20devices%20via%20intune%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3120673%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20both%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F620702%22%20target%3D%22_blank%22%3E%40Rudy_Ooms%3C%2FA%3E%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1209009%22%20target%3D%22_blank%22%3E%40Harm_Veenstra%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20seems%20like%20the%20script%20works%20but%20for%20some%20odd%20reason%20it%20doesn't%20like%20the%20URL%20I%20used%20for%20the%20image.%20this%20image%20opens%20fine%20when%20entering%20on%20a%20incognito%20browser%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Screenshot%202022-02-05%20at%202.58.13%20PM.png%22%20style%3D%22width%3A%20985px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F345537iAF3C1B06FBE94B3B%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Screenshot%202022-02-05%20at%202.58.13%20PM.png%22%20alt%3D%22Screenshot%202022-02-05%20at%202.58.13%20PM.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20I%20have%20got%20it%20working%20a%20long%20way%20but%20it%20works%20even%20though%20the%20script%20fails.on%20intune.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20I%20have%20done%20is%20push%20the%20image%20out%20via%20win32%20app%20to%20go%20into%20the%20location%20c%3A%5CMDM%20then%20the%20script%20does%20the%20rest.%20Even%20though%20this%20works%20I%20think%20the%20script%20is%20failing%20due%20to%20it%20having%20code%20in%20it%20which%20I%20no%20longer%20need%20due%20to%20deploying%20the%20image%20through%20a%20win32%20app.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20ideas%20which%20bit%20i%20need%20to%20remove%3F%20so%20it%20says%20successful%20on%20intune%20rather%20than%20failed%20for%20the%20script%3C%2FP%3E%3C%2FLINGO-BODY%3E
Super 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