Apply Desktop Wallpaper

SOTI MobiControl
Windows

SOTI MobiControl automates proactive IT tasks on Windows 10/11 using scripts. You can create and remotely execute Batch or PowerShell scripts from the SOTI MobiControl console to perform essential operations on devices.

Important:
  • It is recommended to test the script on a local/ test machine for its purpose and effects. 
  • SOTI MobiControl will not be responsible for any damage/loss to the data/setup based on the behavior of the script.

Change the wallpaper of device

1 $filePath = "C:\MobiControl\sample.jpg"
2 function Get-CurrentUser() {
3 try {
4 $currentUser = (Get-Process -IncludeUserName -Name explorer | Select-Object -First 1 | Select-Object -ExpandProperty UserName).Split("\")[1]
5 if (-NOT[string]::IsNullOrEmpty($currentUser)) {
6 Write-Output $currentUser
7 }
8 }
9 catch {
10 Write-Output "Failed to get current user."
11 Write-Host "Error occured while running script -> ",$_.Exception.Message
12 }
13 }
14 function Get-UserSID([string]$fCurrentUser) {
15 try {
16 $user = New-Object System.Security.Principal.NTAccount($fcurrentUser)
17 $sid = $user.Translate([System.Security.Principal.SecurityIdentifier])
18 if (-NOT[string]::IsNullOrEmpty($sid)) {
19 Write-Output $sid.Value
20 }
21 }
22 catch {
23 Write-Output "Failed to get current user SID."
24 Write-Host "Error occured while running script -> ",$_.Exception.Message
25 }
26 }
27 Write-Host "--------------starting script execution--------------"
28 $currentUser = Get-CurrentUser
29 $currentUserSID = Get-UserSID $currentUser
30 $userRegistryPath = "Registry::HKEY_USERS\$($currentUserSID)\Control Panel\Desktop"
31 Set-ItemProperty -Path $userRegistryPath -Name wallpaper -Value $filePath
32 Write-Host "--------------script execution completed successfully--------------"
33 Write-Host "Apply Restart device action to reflect the changes immediately"

Was this helpful?

Need more help?
Ask Community