# PowerShell script to export Start menu layout

The Start menu layout on Windows devices typically consists of a customizable grid of frequently used and pinned applications within the Start menu. Exporting the Start menu layout is particularly helpful for IT admins when configuring the Windows multi-app kiosk policy. The script facilitates the [export of Start menu layout](https://www.hexnode.com/mobile-device-management/help/how-to-lock-down-windows-devices-in-multi-app-kiosk-mode-using-hexnode/#step-3-customize-and-export-start-layout) from Windows devices, which is essential for maintaining a standardized Start menu layout of apps while configuring the kiosk lockdown policy across multiple devices. This process involves exporting the required layout from a reference device and then using it on other devices while configuring the multi-app kiosk policy. The document includes a script to export the Start menu layout on Windows devices, which IT admins can deploy using Hexnode’s [Execute Custom Script](https://www.hexnode.com/mobile-device-management/help/executing-custom-scripts-for-windows/) remote action.

Scripting language – PowerShell

File extension – .ps1

 Disclaimer: 
The sample script provided below is adapted from a third-party open-source site.

 

 Notes:- The script is compatible exclusively with ***Windows 10*** devices.
- Only the currently logged-in user’s Start menu layout is exported.

 

Export Start menu layout
------------------------

Script to export Start menu layout on Windows devices

try{ #determining the current logged in user $currentLoggedInuser="" $signedInUsers=get-wmiobject win32\_process | where-object {$\_.processname -eq "explorer.exe"} | Foreach ({$\_.getowner().user}) foreach($user in $signedInUsers) { $isactive = C:\\windows\\system32\\qwinsta.exe $user if($isactive -like "\* Active\*") { $currentLoggedInuser = $user break } } if($currentLoggedInuser -eq "") { Write-Host "cannot find any logged in user, so skipping script execution`nTo execute this script, atleast one user must be logged-in to the device" } else { Write-Host "The start layout for the user $currentLoggedInuser has been exported successfully." $script = "Start-Process ""$file"" -PassThru -Wait" #unregistering ShowNotificationTask task from task scheduler (if we have already registered using script execution) try { $a=Unregister-ScheduledTask -TaskName "ShowNotificationTask" -Confirm:$false -ErrorAction:Ignore } catch { Write-Host "error while unregistering sheduletask-->",$\_.Exception.Message } #scheduling task $actions = (New-ScheduledTaskAction -Execute 'powershell.exe' -WorkingDirectory C:\\Hexnode\\Logs -Argument "-ExecutionPolicy unrestricted -WindowStyle Hidden -NoLogo -command `"&{Export-StartLayout -Path C:\\Path\\to\\the\\file\\Filename.xml }`"") $principal = New-ScheduledTaskPrincipal -UserId $currentLoggedInuser -RunLevel Highest $settings = New-ScheduledTaskSettingsSet -WakeToRun -DontStopIfGoingOnBatteries -DontStopOnIdleEnd -Hidden -AllowStartIfOnBatteries -Priority 0 -StartWhenAvailable $task = New-ScheduledTask -Action $actions -Principal $principal -Settings $settings $reg= Register-ScheduledTask 'ShowNotificationTask' -InputObject $task Start-ScheduledTask -TaskName "ShowNotificationTask" -Verbose } } catch { Write-Host "Exception inside running script-->",$\_.Exception.Message } 

   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

  try{

 \#determining the current logged in user 

 $currentLoggedInuser=""

 $signedInUsers=get-wmiobject win32\_process | where-object {$\_.processname -eq "explorer.exe"} | Foreach ({$\_.getowner().user})

 foreach($user in $signedInUsers)

 {

 $isactive = C:\\windows\\system32\\qwinsta.exe $user 

 if($isactive -like "\* Active\*")

 {

 $currentLoggedInuser = $user 

 break

 }

 }

 if($currentLoggedInuser -eq "")

 {

 Write-Host "cannot find any logged in user, so skipping script execution`nTo execute this script, atleast one user must be logged-in to the device"

 }

 else

 {

 Write-Host "The start layout for the user $currentLoggedInuser has been exported successfully."

 $script = "Start-Process ""$file"" -PassThru -Wait"

 \#unregistering ShowNotificationTask task from task scheduler (if we have already registered using script execution) 

 try

 {

 $a=Unregister-ScheduledTask -TaskName "ShowNotificationTask" -Confirm:$false -ErrorAction:Ignore

 }

 catch

 {

 Write-Host "error while unregistering sheduletask-->",$\_.Exception.Message

 }

 \#scheduling task 

 $actions = (New-ScheduledTaskAction -Execute 'powershell.exe' -WorkingDirectory C:\\Hexnode\\Logs -Argument "-ExecutionPolicy unrestricted -WindowStyle Hidden -NoLogo -command `"&{Export-StartLayout -Path C:\\Path\\to\\the\\file\\Filename.xml }`"")

 $principal = New-ScheduledTaskPrincipal -UserId $currentLoggedInuser -RunLevel Highest

 $settings = New-ScheduledTaskSettingsSet -WakeToRun -DontStopIfGoingOnBatteries -DontStopOnIdleEnd -Hidden -AllowStartIfOnBatteries -Priority 0 -StartWhenAvailable

 $task = New-ScheduledTask -Action $actions -Principal $principal -Settings $settings

 $reg= Register-ScheduledTask 'ShowNotificationTask' -InputObject $task 

 Start-ScheduledTask -TaskName "ShowNotificationTask" -Verbose

 }

}

catch

{

 Write-Host "Exception inside running script-->",$\_.Exception.Message

} 

   

 

  

The script fetches and saves the Start menu layout for the currently logged-in user account using the `Export-StartLayout` cmdlet. This cmdlet exports the layout of the Start menu as an XML file. The `Export-StartLayout` cmdlet is used with the `-Path` parameter specifying the location and filename where the XML file containing the Start menu layout will be saved. Replace `C:\Path\to\the\file\Filename.xml` with the actual path where you want to save the start layout XML file. Also, replace `Filename.xml` with the desired name for the XML file.

What happens at the device end?
-------------------------------

Upon successful execution of the script, the Start menu layout of the currently logged-in user account will be saved to the specified location on the device. A success message will then be displayed in the Hexnode UEM portal under the Action History tab.

[![Use a script to export the Start menu layout on Windows and verify its output from Hexnode](https://cdn.hexnode.com/mobile-device-management/help/wp-content/uploads/2024/06/Export-Start-menu-layout-on-Windows-with-script-and-verify-its-output.png "Export Start menu layout on Windows with script and verify its output")](https://cdn.hexnode.com/mobile-device-management/help/wp-content/uploads/2024/06/Export-Start-menu-layout-on-Windows-with-script-and-verify-its-output.png)

 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.