# Script to set Wallpaper on Windows

Hexnode UEM automates the execution of proactive IT tasks on Windows with the help of [custom scripts](https://www.hexnode.com/mobile-device-management/help/executing-custom-scripts-for-windows/). For example, you can create Batch file scripts or PowerShell scripts to perform necessary operations, which can be executed on the devices remotely from the Hexnode console.

This doc helps you create custom scripts to change the desktop wallpaper on Windows devices.

 Note: 
**Supported Versions**:

The scripts given below will be supported on the following versions:

- Windows 10 v1607+ (Pro, Enterprise, Education)
- Windows 11 (Pro, Enterprise, Education)

 

 Disclaimer:The sample scripts provided below are adapted from third-party open-source sites.

 

PowerShell script to set the wallpaper
--------------------------------------

Script to change the Wallpaper on Windows

$filePath = "C:\\Hexnode\\sample.jpg" function Get-CurrentUser() { try { $currentUser = (Get-Process -IncludeUserName -Name explorer | Select-Object -First 1 | Select-Object -ExpandProperty UserName).Split("\\")\[1\] if (-NOT\[string\]::IsNullOrEmpty($currentUser)) { Write-Output $currentUser } } catch { Write-Output "Failed to get current user." Write-Output "Error occured while running script -> ",$\_.Exception.Message } } function Get-UserSID(\[string\]$fCurrentUser) { try { $user = New-Object System.Security.Principal.NTAccount($fcurrentUser) $sid = $user.Translate(\[System.Security.Principal.SecurityIdentifier\]) if (-NOT\[string\]::IsNullOrEmpty($sid)) { Write-Output $sid.Value } } catch { Write-Output "Failed to get current user SID." Write-Output "Error occured while running script -> ",$\_.Exception.Message } } Write-Output "--------------starting script execution--------------" $currentUser = Get-CurrentUser $currentUserSID = Get-UserSID $currentUser $userRegistryPath = "Registry::HKEY\_USERS\\$($currentUserSID)\\Control Panel\\Desktop" Set-ItemProperty -Path $userRegistryPath -Name wallpaper -Value $filePath Write-Output "--------------script execution completed successfully--------------" Write-Output "Apply Restart device action to reflect the changes immediately" 

   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

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

  $filePath = "C:\\Hexnode\\sample.jpg"

function Get-CurrentUser() {

 try {

 $currentUser = (Get-Process -IncludeUserName -Name explorer | Select-Object -First 1 | Select-Object -ExpandProperty UserName).Split("\\")\[1\] 

 if (-NOT\[string\]::IsNullOrEmpty($currentUser)) { 

 Write-Output $currentUser 

 } 

 } 

 catch { 

 Write-Output "Failed to get current user." 

 Write-Output "Error occured while running script -> ",$\_.Exception.Message 

 } 

} 

function Get-UserSID(\[string\]$fCurrentUser) { 

 try { 

 $user = New-Object System.Security.Principal.NTAccount($fcurrentUser) 

 $sid = $user.Translate(\[System.Security.Principal.SecurityIdentifier\]) 

 if (-NOT\[string\]::IsNullOrEmpty($sid)) { 

 Write-Output $sid.Value 

 } 

 } 

 catch { 

 Write-Output "Failed to get current user SID." 

 Write-Output "Error occured while running script -> ",$\_.Exception.Message 

 } 

} 

Write-Output "--------------starting script execution--------------" 

$currentUser = Get-CurrentUser 

$currentUserSID = Get-UserSID $currentUser 

$userRegistryPath = "Registry::HKEY\_USERS\\$($currentUserSID)\\Control Panel\\Desktop" 

Set-ItemProperty -Path $userRegistryPath -Name wallpaper -Value $filePath 

Write-Output "--------------script execution completed successfully--------------" 

Write-Output "Apply Restart device action to reflect the changes immediately" 

   

 

  

![Script to set wallpaper remotely on Windows executed successfully from Hexnode.](https://cdn.hexnode.com/mobile-device-management/help/wp-content/uploads/2022/03/Wallpaper-set-remotely-on-Windows-with-script--300x149.png)

Replace file path in the ***$filePath*** parameter with your actual file path and ensure the wallpaper image exists on the device by the specified name at the designated path. Since the script works on this image, its unavailability can cause the action to fail. Also, it requires a [restart](https://www.hexnode.com/mobile-device-management/help/restart-a-device-using-hexnode-mdm/) action for the changes to be reflected on the device.

How to View Script Output in Hexnode
------------------------------------

To review the execution results, navigate to the **Action History** tab of the specific device in your Hexnode UEM portal. Locate the script entry in the **Subject** column and click the **Show Output** button next to the status field to view the returned data.

 Notes:- It is recommended to manually validate the script execution on a system before executing the action in bulk.
- Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.