Forum Discussion
unable to change backgroud on devices via intune
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
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
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