Posted On October 6, 2021

PowerShell: Set Windows Scheduled Task to Send a Pop-up Message

kimconnect 0 comments
blog.KimConnect.com >> Windows >> PowerShell: Set Windows Scheduled Task to Send a Pop-up Message
# Set variables
$taskName='Bi-weekly Meeting Reminder'
$time='11:50am'
$daily=New-ScheduledTaskTrigger -Daily -At $time
$everyOtherDay=New-ScheduledTaskTrigger -Daily -DaysInterval 2 -At $time
$biWeekly=New-ScheduledTaskTrigger -Weekly -WeeksInterval 2 -DaysOfWeek Wednesday -At $time
$atLogon=New-ScheduledTaskTrigger -AtLogon

# Command to send a message to user by name
$username='kim'
$command="Send-RDUserMessage -HostServer $env:computername -UnifiedSessionID (query session $username /SERVER:$env:computername|select -skip 1|%{`$_.Split(' ',[System.StringSplitOptions]::RemoveEmptyEntries)})[2] -MessageTitle 'Scheduled Task' -MessageBody '$taskName'"

$principal = New-ScheduledTaskPrincipal -UserID "NT AUTHORITY\SYSTEM" -LogonType ServiceAccount -RunLevel Highest
$settings=New-ScheduledTaskSettingsSet -MultipleInstances IgnoreNew -ExecutionTimeLimit 0
#$action=New-ScheduledTaskAction -Execute "Powershell.exe" -Argument "-ExecutionPolicy Bypass $scriptFile"
#$action=New-ScheduledTaskAction -Execute 'PowerShell.exe' -Argument "Add-Type -AssemblyName PresentationFramework;[System.Windows.MessageBox]::Show('$taskName')"
$action=New-ScheduledTaskAction -Execute 'PowerShell.exe' -Argument $command

# Unregister the Scheduled task if it already exists
Get-ScheduledTask $taskName -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$false;

# Create new scheduled task
Register-ScheduledTask -Action $action -Trigger $biWeekly -TaskName $taskName -Settings $settings -Principal $principal

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

Two Useful Workstation Shortcuts for Non-Savvy Users

Lockdown: %windir%\system32\rundll32.exe user32.dll,LockWorkStation Shutdown: shutdown -s -m \\computername -t 7200

Active Directory Group Policy – HIPPA Auditing

The Health Insurance Portability and Accountability Act of 1996 (HIPAA) is a federal law that required the…

How to Change iTunes Backup Location of Storage In Windows

Make a directory junction after moving the backup storage location robocopy "C:\Users\%USERNAME%\AppData\Roaming\Apple Computer\MobileSync" "D:\iphone_backups" /E…
Other project: DragonCoin.com