# Script to send scheduled notifications to Windows device

Organizations manage a large workforce and numerous devices, which demands the need for seamless communication. Hence, sending notifications to devices is a timeless requirement. Such notifications can range from reminder messages for upcoming meetings, alerts regarding a suspected security breach to warnings about potential Wi-Fi outages. It would be convenient if IT administrators could just enter the content of the notification and push it to all devices simultaneously. Even better, they could schedule these notifications for a specific time in the future, eliminating any risks associated with time-sensitive messages. With Hexnode UEM, they can do so for Windows devices by running the script given below using the [Execute Custom Script](https://www.hexnode.com/mobile-device-management/help/executing-custom-scripts-for-windows/) action.

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

 

PowerShell script to schedule notifications
-------------------------------------------

### Display notification as pop-up box

Script to schedule and display notification as pop-up box

$command = { \[System.Reflection.Assembly\]::LoadWithPartialName('System.Windows.Forms') \[System.Windows.Forms.MessageBox\]::Show('Team meeting in an hour!','REMINDER') } $user = "QA" Unregister-Scheduledtask -taskname "NewTask" -Confirm:$false -ErrorAction:Ignore #$actions = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument $command $actions = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument "-ExecutionPolicy unrestricted -WindowStyle Hidden -NoLogo -Command $command" $principal = New-ScheduledTaskPrincipal -UserId $user -RunLevel Highest $settings = New-ScheduledTaskSettingsSet -WakeToRun -DontStopIfGoingOnBatteries -DontStopOnIdleEnd -Hidden -AllowStartIfOnBatteries -Priority 0 -StartWhenAvailable $trigger = New-ScheduledTaskTrigger -Once -At 2:25pm $task = New-ScheduledTask -Action $actions -Principal $principal -Settings $settings -Trigger $trigger $reg= Register-ScheduledTask -TaskName "NewTask" -InputObject $task

   1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

  $command = {

 \[System.Reflection.Assembly\]::LoadWithPartialName('System.Windows.Forms')

 \[System.Windows.Forms.MessageBox\]::Show('Team meeting in an hour!','REMINDER')

 }

$user = "QA"

Unregister-Scheduledtask -taskname "NewTask" -Confirm:$false -ErrorAction:Ignore

\#$actions = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument $command

$actions = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument "-ExecutionPolicy unrestricted -WindowStyle Hidden -NoLogo -Command $command"

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

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

$trigger = New-ScheduledTaskTrigger -Once -At 2:25pm

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

$reg= Register-ScheduledTask -TaskName "NewTask" -InputObject $task

   

 

  

### Display notification as toast message

Script to schedule and display notification as toast messages

$command = { \[reflection.assembly\]::loadwithpartialname('System.Windows.Forms') \[reflection.assembly\]::loadwithpartialname('System.Drawing') $notify = new-object system.windows.forms.notifyicon $notify.icon = \[System.Drawing.SystemIcons\]::Information $notify.visible = $true $notify.showballoontip(10,'REMINDER','Team meeting in an hour!',\[system.windows.forms.tooltipicon\]::None) } $user = "QA" Unregister-Scheduledtask -taskname "NewTask" -Confirm:$false -ErrorAction:Ignore #$actions = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument $command $actions = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument "-ExecutionPolicy unrestricted -WindowStyle Hidden -NoLogo -Command $command" $principal = New-ScheduledTaskPrincipal -UserId $user -RunLevel Highest $settings = New-ScheduledTaskSettingsSet -WakeToRun -DontStopIfGoingOnBatteries -DontStopOnIdleEnd -Hidden -AllowStartIfOnBatteries -Priority 0 -StartWhenAvailable $trigger = New-ScheduledTaskTrigger -Once -At 2:25pm $task = New-ScheduledTask -Action $actions -Principal $principal -Settings $settings -Trigger $trigger $reg= Register-ScheduledTask -TaskName "NewTask" -InputObject $task

   1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

  $command = {

\[reflection.assembly\]::loadwithpartialname('System.Windows.Forms')

\[reflection.assembly\]::loadwithpartialname('System.Drawing')

$notify = new-object system.windows.forms.notifyicon

$notify.icon = \[System.Drawing.SystemIcons\]::Information

$notify.visible = $true

$notify.showballoontip(10,'REMINDER','Team meeting in an hour!',\[system.windows.forms.tooltipicon\]::None)

}

$user = "QA"

Unregister-Scheduledtask -taskname "NewTask" -Confirm:$false -ErrorAction:Ignore

\#$actions = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument $command

$actions = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument "-ExecutionPolicy unrestricted -WindowStyle Hidden -NoLogo -Command $command"

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

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

$trigger = New-ScheduledTaskTrigger -Once -At 2:25pm

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

$reg= Register-ScheduledTask -TaskName "NewTask" -InputObject $task

   

 

  

In the scripts given above, replace *Team meeting in an hour* with the content of the notification and *REMINDER* with the required title. Replace *QA* with the username of the device and *2:25pm* with the stipulated time to send the notification.

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

On executing the script, the configured message will be displayed on the device at the scheduled time, provided the specified user is logged in.

### Pop-up box notifications

![scheduled notification displayed on device end as pop-up box](https://cdn.hexnode.com/mobile-device-management/help/wp-content/uploads/2023/07/Output-of-script-to-schedule-and-display-pop-up-notifications.png "Output of script to schedule and display pop-up notifications")[](https://cdn.hexnode.com/mobile-device-management/help/wp-content/uploads/2023/07/Output-of-script-to-schedule-and-display-pop-up-notifications.png)

### Toast notifications

![scheduled message displayed on device end as toast message](https:2023/07/Output-of-script-to-schedule-and-display-toast-notifications.png "Output of script to schedule and display toast notifications")[](https:2023/07/Output-of-script-to-schedule-and-display-toast-notifications.png)