Added support for RunOnce and RunOncePerDay features
This commit is contained in:
parent
4b6d3b8c5b
commit
042d1ad590
7 changed files with 97 additions and 27 deletions
|
|
@ -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
|
||||
- <Option Name="Action" Value="ToastRunUpdateID:" />
|
||||
- <Option Name="Action" Value="ToastRunPackageID:" />
|
||||
- <Option Name="Action" Value="ToastRunApplicationID:" />
|
||||
- <Option Name="Action" Value="ToastReboot:" />
|
||||
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:
|
||||
- <Option Name="RunUpdateID" Enabled="True" Value="3012973" />
|
||||
- <Option Name="RunUpdateTitle" Enabled="True" Value="Version 1909" />
|
||||
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
|
||||
- <Option Name="Action" Value="ToastRunUpdateID:" />
|
||||
- <Option Name="Action" Value="ToastRunPackageID:" />
|
||||
- <Option Name="Action" Value="ToastRunApplicationID:" />
|
||||
- <Option Name="Action" Value="ToastReboot:" />
|
||||
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:
|
||||
- <Option Name="RunUpdateID" Enabled="True" Value="3012973" />
|
||||
- <Option Name="RunUpdateTitle" Enabled="True" Value="Version 1909" />
|
||||
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"
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
<Feature Name="PendingRebootUptime" Enabled="False" /> <!-- Enables the toast for reminding users of restarting their device if it exceeds the uptime defined in MaxUptimeDays -->
|
||||
<Feature Name="PendingRebootCheck" Enabled="False" /> <!-- Enables the toast for reminding users of pending reboots found in registry/WMI. Might not suit ConfigMgr all too well, as if a pending reboot is found, further deployments won't run -->
|
||||
<Feature Name="ADPasswordExpiration" Enabled="True" /> <!-- Enables the toast for reminding users of expiring Active Directory passwords -->
|
||||
<Feature Name="RunOncePerDay" Enabled="False" /> <!-- Ensures that the toast will be displayed no more than one time each day -->
|
||||
<Feature Name="RunOnce" Enabled="False" /> <!-- Ensures that the toast will be displayed no more than one time each day -->
|
||||
<Option Name="TargetOS" Build="19041" /> <!-- The actual build number of the targeted OS. 19041 = 2004 | 18363 = 1909 | 18362 = 1903 | 17763 = 1809. This option has no effect if OSUpgrade is set to False -->
|
||||
<Option Name="MaxUptimeDays" Value="-6" /> <!-- When using the toast for checking for pending reboots. A reboot is considered pending if computer uptime exceeds the value set here -->
|
||||
<Option Name="PendingRebootUptimeText" Enabled="False" /> <!-- Adds an additional group to the toast with text about the uptime of the computer -->
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
<Feature Name="PendingRebootUptime" Enabled="False" /> <!-- Enables the toast for reminding users of restarting their device if it exceeds the uptime defined in MaxUptimeDays -->
|
||||
<Feature Name="PendingRebootCheck" Enabled="False" /> <!-- Enables the toast for reminding users of pending reboots found in registry/WMI. Might not suit ConfigMgr all too well, as if a pending reboot is found, further deployments won't run -->
|
||||
<Feature Name="ADPasswordExpiration" Enabled="False" /> <!-- Enables the toast for reminding users of expiring Active Directory passwords -->
|
||||
<Feature Name="RunOncePerDay" Enabled="False" /> <!-- Ensures that the toast will be displayed no more than one time each day -->
|
||||
<Feature Name="RunOnce" Enabled="False" /> <!-- Ensures that the toast will be displayed no more than one time each day -->
|
||||
<Option Name="TargetOS" Build="19041" /> <!-- The actual build number of the targeted OS. 19041 = 2004 | 18363 = 1909 | 18362 = 1903 | 17763 = 1809. This option has no effect if OSUpgrade is set to False -->
|
||||
<Option Name="MaxUptimeDays" Value="-6" /> <!-- When using the toast for checking for pending reboots. A reboot is considered pending if computer uptime exceeds the value set here -->
|
||||
<Option Name="PendingRebootUptimeText" Enabled="False" /> <!-- Adds an additional group to the toast with text about the uptime of the computer -->
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
<Feature Name="PendingRebootUptime" Enabled="False" /> <!-- Enables the toast for reminding users of restarting their device if it exceeds the uptime defined in MaxUptimeDays -->
|
||||
<Feature Name="PendingRebootCheck" Enabled="False" /> <!-- Enables the toast for reminding users of pending reboots found in registry/WMI. Might not suit ConfigMgr all too well, as if a pending reboot is found, further deployments won't run -->
|
||||
<Feature Name="ADPasswordExpiration" Enabled="False" /> <!-- Enables the toast for reminding users of expiring Active Directory passwords -->
|
||||
<Feature Name="RunOncePerDay" Enabled="False" /> <!-- Ensures that the toast will be displayed no more than one time each day -->
|
||||
<Feature Name="RunOnce" Enabled="False" /> <!-- Ensures that the toast will be displayed no more than one time each day -->
|
||||
<Option Name="TargetOS" Build="19043" /> <!-- The actual build number of the targeted OS. 19041 = 2004 | 18363 = 1909 | 18362 = 1903 | 17763 = 1809. This option has no effect if OSUpgrade is set to False -->
|
||||
<Option Name="MaxUptimeDays" Value="-6" /> <!-- When using the toast for checking for pending reboots. A reboot is considered pending if computer uptime exceeds the value set here -->
|
||||
<Option Name="PendingRebootUptimeText" Enabled="False" /> <!-- Adds an additional group to the toast with text about the uptime of the computer -->
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
<Feature Name="PendingRebootUptime" Enabled="True" /> <!-- Enables the toast for reminding users of restarting their device if it exceeds the uptime defined in MaxUptimeDays -->
|
||||
<Feature Name="PendingRebootCheck" Enabled="False" /> <!-- Enables the toast for reminding users of pending reboots found in registry/WMI. Might not suit ConfigMgr all too well, as if a pending reboot is found, further deployments won't run -->
|
||||
<Feature Name="ADPasswordExpiration" Enabled="False" /> <!-- Enables the toast for reminding users of expiring Active Directory passwords -->
|
||||
<Feature Name="RunOncePerDay" Enabled="False" /> <!-- Ensures that the toast will be displayed no more than one time each day -->
|
||||
<Feature Name="RunOnce" Enabled="False" /> <!-- Ensures that the toast will be displayed no more than one time each day -->
|
||||
<Option Name="TargetOS" Build="19041" /> <!-- The actual build number of the targeted OS. 19041 = 2004 | 18363 = 1909 | 18362 = 1903 | 17763 = 1809. This option has no effect if OSUpgrade is set to False -->
|
||||
<Option Name="MaxUptimeDays" Value="-6" /> <!-- When using the toast for checking for pending reboots. A reboot is considered pending if computer uptime exceeds the value set here -->
|
||||
<Option Name="PendingRebootUptimeText" Enabled="True" /> <!-- Adds an additional group to the toast with text about the uptime of the computer -->
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
<Feature Name="PendingRebootUptime" Enabled="False" /> <!-- Enables the toast for reminding users of restarting their device if it exceeds the uptime defined in MaxUptimeDays -->
|
||||
<Feature Name="PendingRebootCheck" Enabled="False" /> <!-- Enables the toast for reminding users of pending reboots found in registry/WMI. Might not suit ConfigMgr all too well, as if a pending reboot is found, further deployments won't run -->
|
||||
<Feature Name="ADPasswordExpiration" Enabled="False" /> <!-- Enables the toast for reminding users of expiring Active Directory passwords -->
|
||||
<Feature Name="RunOncePerDay" Enabled="False" /> <!-- Ensures that the toast will be displayed no more than one time each day -->
|
||||
<Feature Name="RunOnce" Enabled="False" /> <!-- Ensures that the toast will be displayed no more than one time each day -->
|
||||
<Option Name="TargetOS" Build="19042" /> <!-- The actual build number of the targeted OS. 19041 = 2004 | 18363 = 1909 | 18362 = 1903 | 17763 = 1809. This option has no effect if OSUpgrade is set to False -->
|
||||
<Option Name="MaxUptimeDays" Value="-6" /> <!-- When using the toast for checking for pending reboots. A reboot is considered pending if computer uptime exceeds the value set here -->
|
||||
<Option Name="PendingRebootUptimeText" Enabled="False" /> <!-- Adds an additional group to the toast with text about the uptime of the computer -->
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
<Feature Name="PendingRebootUptime" Enabled="True" /> <!-- Enables the toast for reminding users of restarting their device if it exceeds the uptime defined in MaxUptimeDays -->
|
||||
<Feature Name="PendingRebootCheck" Enabled="False" /> <!-- Enables the toast for reminding users of pending reboots found in registry/WMI. Might not suit ConfigMgr all too well, as if a pending reboot is found, further deployments won't run -->
|
||||
<Feature Name="ADPasswordExpiration" Enabled="False" /> <!-- Enables the toast for reminding users of expiring Active Directory passwords -->
|
||||
<Feature Name="RunOncePerDay" Enabled="False" /> <!-- Ensures that the toast will be displayed no more than one time each day -->
|
||||
<Feature Name="RunOnce" Enabled="False" /> <!-- Ensures that the toast will be displayed no more than one time each day -->
|
||||
<Option Name="TargetOS" Build="19041" /> <!-- The actual build number of the targeted OS. 19041 = 2004 | 18363 = 1909 | 18362 = 1903 | 17763 = 1809. This option has no effect if OSUpgrade is set to False -->
|
||||
<Option Name="MaxUptimeDays" Value="-6" /> <!-- When using the toast for checking for pending reboots. A reboot is considered pending if computer uptime exceeds the value set here -->
|
||||
<Option Name="PendingRebootUptimeText" Enabled="True" /> <!-- Adds an additional group to the toast with text about the uptime of the computer -->
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue