diff --git a/New-ToastNotification.ps1 b/New-ToastNotification.ps1
index 5ebd36c..bf3cddb 100644
--- a/New-ToastNotification.ps1
+++ b/New-ToastNotification.ps1
@@ -82,18 +82,18 @@
** As well as added support for dynamic deadline retrieval for software updates **
** Stuff has been rewritten to suit my understanding and thoughts of the script **
- 2.0.0 - Huge changes to how this script handles custom protocols
- Added Support for Custom Actions/Protocols within the script under user context removing the need for that to be run under SYSTEM/ADMIN
- -
- -
- -
- -
- Added Support to dynamically create Custom Action Scripts to support Custom Protocols
- Added Support for Software (Feature) Updates : Searches for an update and will store in variable
- Added new XML Types for Software Updates:
- -
- -
- Added support for getting deadline date/time dynamically for software updates
+ 2.0.0 - Huge changes to how this script handles custom protocols
+ Added Support for Custom Actions/Protocols within the script under user context removing the need for that to be run under SYSTEM/ADMIN
+ -
+ -
+ -
+ -
+ Added Support to dynamically create Custom Action Scripts to support Custom Protocols
+ Added Support for Software (Feature) Updates : Searches for an update and will store in variable
+ Added new XML Types for Software Updates:
+ -
+ -
+ Added support for getting deadline date/time dynamically for software updates
- Configure DynamicDeadline with the UpdateID
2.0.1 - Updated custom action scripts!
@@ -106,7 +106,7 @@
- If newer version is available from the script, new custom action scripts will be created
- This allows me to make sure the relevant scripts are in place in case I change something along the way
- Modified script output of custom script for RunPackageID to pick up Program ID dynamically
- Added support for getting deadline date/time dynamically for applications
+ Added support for getting deadline date/time dynamically for applications
- Configure DynamicDeadline with the Application ID
2.0.2 - Fixed an error in the custom protocols
@@ -267,21 +267,21 @@ function Get-GivenName() {
if (Get-Service -Name ccmexec -ErrorAction SilentlyContinue) {
Write-Log -Message "Looking for logged on user's SID in WMI with CCM client"
$LoggedOnSID = Get-CimInstance -Namespace ROOT\CCM -Class CCM_UserLogonEvents -Filter "LogoffTime=null" | Select -ExpandProperty UserSID
- if ($LoggedOnSID.GetType().IsArray) {
- Write-Log -Message "Multiple SID's found logged on. Skipping"
- $GivenName = $null
+ if ($LoggedOnSID.GetType().IsArray) {
+ Write-Log -Message "Multiple SID's found logged on. Skipping"
+ $GivenName = $null
}
- else {
- $RegKey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\SessionData"
- $DisplayName = (Get-ChildItem -Path $RegKey | Where-Object {$_.GetValue("LoggedOnUserSID") -eq $LoggedOnSID} | Select-Object -First 1).GetValue("LoggedOnDisplayName")
- if ($DisplayName) {
- $GivenName = $DisplayName.Split()[0].Trim()
- Write-Log -Message "Given name found matching logged on user SID: $GivenName"
- $GivenName
- }
- else {
- $GivenName = $null
- }
+ else {
+ $RegKey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\SessionData"
+ $DisplayName = (Get-ChildItem -Path $RegKey | Where-Object {$_.GetValue("LoggedOnUserSID") -eq $LoggedOnSID} | Select-Object -First 1).GetValue("LoggedOnDisplayName")
+ if ($DisplayName) {
+ $GivenName = $DisplayName.Split()[0].Trim()
+ Write-Log -Message "Given name found matching logged on user SID: $GivenName"
+ $GivenName
+ }
+ else {
+ $GivenName = $null
+ }
}
}
}
@@ -730,6 +730,7 @@ function Display-ToastNotification() {
Write-Log -Message "All good. Toast notification was displayed"
# Using Write-Output for sending status to IME log when used with Endpoint Analytics in Intune
Write-Output "All good. Toast notification was displayed"
+ Save-NotifificationTimeStamp
if ($CustomAudio -eq "True") {
Invoke-Command -ScriptBlock {
Add-Type -AssemblyName System.Speech
@@ -1116,6 +1117,42 @@ exit 0
}
}
+######### CUSTOM FUNCTIONS #########
+# Create function to retrieve the number of days since the notification last ran for the logged on user
+function Get-DaysSinceLastRun {
+ Write-Log -Message "Running Get-DaysSinceLastRun function"
+ $LocalCulture = Get-Culture
+ $RegionDateFormat = [System.Globalization.CultureInfo]::GetCultureInfo($LocalCulture.LCID).DateTimeFormat.FullDateTimePattern
+ $LastRunDate = (Get-ItemProperty "$LastRunRegistryPath" -Name LastRunDate -ErrorAction Ignore).LastRunDate
+
+ if ($null -eq $LastRunDate) {
+ Write-Log -Message 'No last run time found. Returning $null'
+ return $null
+ }
+ else {
+ $Today = Get-Date -f "$RegionDateFormat"
+ $DateDiff = New-TimeSpan -Start $Today -End (Get-Date $LastRunDate -f "$RegionDateFormat")
+ Write-Log -Message "Last run date = $LastRunDate ($($DateDiff.Days) days ago)"
+ $DateDiff.Days
+ }
+}
+
+# Create function to store the timestamp of the notification execution
+function Save-NotifificationTimeStamp {
+ Write-Log -Message "Storing the run time for the toast notification in registry"
+ $LocalCulture = Get-Culture
+ $RegionDateFormat = [System.Globalization.CultureInfo]::GetCultureInfo($LocalCulture.LCID).DateTimeFormat.FullDateTimePattern
+ $RunTime = Get-Date -f "$RegionDateFormat"
+ If(-not (Test-Path $LastRunRegistryPath)) {
+ New-Item -Path $LastRunRegistryPath -Force | Out-Null
+ }
+ If(-not (Get-ItemProperty -Path $LastRunRegistryPath -Name LastRunDate -ErrorAction Ignore)) {
+ New-ItemProperty -Path $LastRunRegistryPath -Name 'LastRunDate' -Value $RunTime -Force | Out-Null
+ }
+ Else {
+ Set-ItemProperty -Path $LastRunRegistryPath -Name 'LastRunDate' -Value $RunTime -Force
+ }
+}
######### GENERAL VARIABLES #########
# Global variables
# Setting global script version
@@ -1258,6 +1295,8 @@ if(-NOT[string]::IsNullOrEmpty($Xml)) {
$PendingRebootUptime = $Xml.Configuration.Feature | Where-Object {$_.Name -like 'PendingRebootUptime'} | Select-Object -ExpandProperty 'Enabled'
$PendingRebootCheck = $Xml.Configuration.Feature | Where-Object {$_.Name -like 'PendingRebootCheck'} | Select-Object -ExpandProperty 'Enabled'
$ADPasswordExpiration = $Xml.Configuration.Feature | Where-Object {$_.Name -like 'ADPasswordExpiration'} | Select-Object -ExpandProperty 'Enabled'
+ $RunOncePerDay = $Xml.Configuration.Feature | Where-Object {$_.Name -like 'RunOncePerDay'} | Select-Object -ExpandProperty 'Enabled'
+ $RunOnce = $Xml.Configuration.Feature | Where-Object {$_.Name -like 'RunOnce'} | Select-Object -ExpandProperty 'Enabled'
# Load Toast Notification options
$PendingRebootUptimeTextEnabled = $Xml.Configuration.Option | Where-Object {$_.Name -like 'PendingRebootUptimeText'} | Select-Object -ExpandProperty 'Enabled'
$MaxUptimeDays = $Xml.Configuration.Option | Where-Object {$_.Name -like 'MaxUptimeDays'} | Select-Object -ExpandProperty 'Value'
@@ -1267,6 +1306,8 @@ if(-NOT[string]::IsNullOrEmpty($Xml)) {
$TargetOS = $Xml.Configuration.Option | Where-Object {$_.Name -like 'TargetOS'} | Select-Object -ExpandProperty 'Build'
$DeadlineEnabled = $Xml.Configuration.Option | Where-Object {$_.Name -like 'Deadline'} | Select-Object -ExpandProperty 'Enabled'
$DeadlineContent = $Xml.Configuration.Option | Where-Object {$_.Name -like 'Deadline'} | Select-Object -ExpandProperty 'Value'
+ $LastRunRegistryPath = $Xml.Configuration.Option | Where-Object {$_.Name -like 'LastRunRegistryPath'} | Select-Object -ExpandProperty 'Value'
+ $LastRunRegistryPath = "$($global:RegistryPath)\$LastRunRegistryPath"
$DynDeadlineEnabled = $Xml.Configuration.Option | Where-Object {$_.Name -like 'DynamicDeadline'} | Select-Object -ExpandProperty 'Enabled'
$DynDeadlineValue = $Xml.Configuration.Option | Where-Object {$_.Name -like 'DynamicDeadline'} | Select-Object -ExpandProperty 'Value'
# Creating Scripts and Protocols
@@ -1364,6 +1405,23 @@ if ($ToastEnabled -ne "True") {
Write-Log -Message "Toast notification is not enabled. Please check $Config file"
Exit 1
}
+
+If($RunOnce -eq "True") {
+ # Check if notification has already run for this user on this computer
+ $DaysSinceLastRun = Get-DaysSinceLastRun
+ if ($null -ne $DaysSinceLastRun) {
+ Write-Log -Message "Toast notification has already run for this user on this computer. Skipping it"
+ Exit 1
+ }
+}
+If($RunOncePerDay -eq "True") {
+ # Check if last notification run for the logged on user was at least the day before
+ $DaysSinceLastRun = Get-DaysSinceLastRun
+ if ($DaysSinceLastRun -eq 0) {
+ Write-Log -Message "Toast notification has already run today. Skipping until at least tomorrow"
+ Exit 1
+ }
+}
# Checking for conflicts in config. Some combinations makes no sense, thus trying to prevent those from happening
if (($UpgradeOS -eq "True") -AND ($PendingRebootCheck -eq "True")) {
Write-Log -Level Error -Message "Error. Conflicting selection in the $Config file"
diff --git a/config-toast-adpwexpiration.xml b/config-toast-adpwexpiration.xml
index 47cb7da..21feb26 100644
--- a/config-toast-adpwexpiration.xml
+++ b/config-toast-adpwexpiration.xml
@@ -5,6 +5,8 @@
+
+
diff --git a/config-toast-officeupgrade.xml b/config-toast-officeupgrade.xml
index b4cf2c7..53b6655 100644
--- a/config-toast-officeupgrade.xml
+++ b/config-toast-officeupgrade.xml
@@ -5,6 +5,8 @@
+
+
diff --git a/config-toast-osupgrade.xml b/config-toast-osupgrade.xml
index b86eb87..449e80c 100644
--- a/config-toast-osupgrade.xml
+++ b/config-toast-osupgrade.xml
@@ -5,6 +5,8 @@
+
+
diff --git a/config-toast-rebootpending.xml b/config-toast-rebootpending.xml
index 5c6f4b4..f961c3f 100644
--- a/config-toast-rebootpending.xml
+++ b/config-toast-rebootpending.xml
@@ -5,6 +5,8 @@
+
+
diff --git a/config-toast-waasfu.xml b/config-toast-waasfu.xml
index 8882021..9217901 100644
--- a/config-toast-waasfu.xml
+++ b/config-toast-waasfu.xml
@@ -5,6 +5,8 @@
+
+
diff --git a/config-toast.xml b/config-toast.xml
index 5e041ca..76b233a 100644
--- a/config-toast.xml
+++ b/config-toast.xml
@@ -5,6 +5,8 @@
+
+