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

How To Use Command Line to Configure iDrac Settings

Step 1: Install RacADM $computerlist=@' SERVER1 SERVER2 '@ $computernames=@($computerlist -split "`n")|%{$_.Trim()} $fileURL="https://dl.dell.com/FOLDER08543783M/1/DellEMC-iDRACTools-Web-WINX64-10.3.0.0-4945.exe" $expectedExecutable='racadm.exe' $expectedInstallPath='C:\Program Files\Dell\SysMgt\iDRACTools\racadm'…

Manually Dealing with Windows Updates

This unabridged note contains some usable copy/paste lines to work with Windows updates. There's a…

IP Helper Address

What is it and how to use it? When the DHCP Server is placed on…