Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save ahpooch/09405c468cd7b8478fd85f712d341ef3 to your computer and use it in GitHub Desktop.

Select an option

Save ahpooch/09405c468cd7b8478fd85f712d341ef3 to your computer and use it in GitHub Desktop.
This script is meant to be a Discovery Script in Configuration Item of SCCM Baseline that preparing files and scheduled tasks for ToastNotificationScript company workflow
<#
.DESCRIPTION
This script is meant to be a Discovery Script in Configuration Item of SCCM Baseline that
preparing files and scheduled tasks for ToastNotificationScript company workflow
.LINK https://www.imab.dk/windows-10-toast-notification-script/
#>
### Setting variables
$CompanyName = "MyCompany"
$LocalScriptFilesPath = "C:\Windows\AdminScripts\ToastNotificationScript"
$ServerName = "Server1"
$ScriptShare = "NotificationScriptShare$"
$ScriptVersion = "2.3.0"
$RemoteScriptFilePath = "\\$Servername\$ScriptShare\ToastNotificationScript$ScriptVersion"
### Working With files
# Sync LocalScriptFilesPath with RemoteScriptFilesPath
& robocopy $RemoteScriptFilePath $LocalScriptFilesPath "New-ToastNotification.ps1" "Hidden-ROWI.vbs" "RunToastHidden-$CompanyName-*.cmd" /Purge | Out-Null
& robocopy "$RemoteScriptFilePath\Images" "$LocalScriptFilesPath\Images" /Purge | Out-Null
### Working with Scheduled Tasks
$TaskPath = "\ToastNotificationScript\"
# Getting .cmd files in $LocalScriptFilesPath
$Notification_Cases = Get-ChildItem $LocalScriptFilesPath -Filter "RunToastHidden-$CompanyName-*.cmd"
# Unregistering all previously scheduled tasks in $TaskPath
Get-ScheduledTask -TaskPath $TaskPath | Unregister-ScheduledTask -Confirm:$false
#Registering scheduled task for every .cmd file in $LocalScriptFilesPath
foreach($NC in $Notification_Cases){
# Action form ScheduledTask
$action = New-ScheduledTaskAction -Execute 'wscript.exe' -Argument "$LocalScriptFilesPath\Hidden-$CompanyName.vbs $LocalScriptFilesPath\$($NC.Name)"
# Using RandomDelay to stretch in time Popup appearance
$trigger = New-ScheduledTaskTrigger -Daily -DaysInterval 1 -At "09:00" -RandomDelay "00:30"
$trigger.Repetition = $(New-ScheduledTaskTrigger -Once -RandomDelay "00:15" -At "09:00" -RepetitionDuration "13:00" -RepetitionInterval "02:00").Repetition
# UserId will be Domain\CurrentUser if script is exetuted in UserContext
$principal = New-ScheduledTaskPrincipal -UserId $(Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object -expand UserName) -LogonType ServiceAccount -RunLevel Highest
# Win8 is Windows 10 Compatibility Level
$settings = New-ScheduledTaskSettingsSet -Hidden -Compatibility Win8 -DontStopIfGoingOnBatteries -AllowStartIfOnBatteries -MultipleInstances IgnoreNew -StartWhenAvailable
# Constructing ScheduledTask
$task = New-ScheduledTask -Action $action -Principal $principal -Trigger $trigger -Settings $settings
# File name without extension
$taskName = $NC.BaseName
# Registering ScheduledTask in folder "\ToastNotificationScript"
Register-ScheduledTask -TaskName $taskName -InputObject $task -TaskPath $TaskPath -Force | Out-Null
}
Write-Output "Deployed"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment