Bij veel verschillende klanten komt het wel voor dat gebruikers niet altijd hun machines herstarten en dat ze weken to zo wel maanden lang geen herstart hebben gehad. Hierdoor kan het voorkomen dat ze bepaalde updates niet krijgen of niet goed werken. meestal omdat ze de melding wegklikken.
Om de gebruikers inzicht hierin te geven heb ik een Intune Proactive Remediation geschreven/bewerkt die de gebruiker een melding geeft na 7 dagen en dan elke dag er na. Dat het tijd wordt om de computer opnieuw op te starten.
function Display-ToastNotification() {
$Load = [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]
$Load = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]
# Load the notification into the required format
$ToastXML = New-Object -TypeName Windows.Data.Xml.Dom.XmlDocument
$ToastXML.LoadXml($Toast.OuterXml)
# Display the toast notification
try {
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($App).Show($ToastXml)
}
catch {
Write-Output -Message ‘Something went wrong when script whants to displaying the toast notification’ -Level Warn
Write-Output -Message ‘Make sure the script is running as the logged on user’ -Level Warn
}
}
# Setting image variables
$LogoImageUri = “https://www.unen.nl/XXXX/XXXXX__60x60.png”
$LogoImage = “$env:TEMP\ToastLogoImage.png”
$Header_type = “GIF”
$URL = “https://www.unen.nl/XXXXX/scareboot.gif”
$Uptime= get-computerinfo | Select-Object OSUptime
Invoke-WebRequest -Uri $LogoImageUri -OutFile $LogoImage
$Scenario = ‘reminder’ # <!– Possible values are: reminder | short | long –>
$SCAGetSystemLanguage = Get-WinSystemLocale
$SCAGetSystemLanguage = $SCAGetSystemLanguage.Name
if ($SCAGetSystemLanguage -like “*NL*”){
$AttributionText = “xxxxxxxx “
$HeaderText = “Computer herstart is nodig!”
$TitleText = “Uw computer is als laatst herstert $($Uptime.OsUptime.Days) dagen geleden”
$BodyText1 = “Om prestatie- en stabiliteitsredenen raden we aan om minstens één keer per week opnieuw op te starten.”
$BodyText2 = “Sla uw werk op en start uw apparaat vandaag nog opnieuw op. Alvast bedankt”
$BodyText3 = “Voor vragen kunt u contact opnemen met servicedesk”
$BodyText4 = “xxxxxxxx”
}
else{
# Load Toast Notification text
$AttributionText = “Titel “
$HeaderText = “Computer Restart is needed!”
$TitleText = “Your device has not performed a reboot in the last $($Uptime.OsUptime.Days) days”
$BodyText1 = “For performance and stability reasons we suggest a reboot at least once a week.”
$BodyText2 = “Please save your work and restart your device today. Thank you in advance.”
$BodyText3 = “For any questions please cal our servicedesk”
$BodyText4 = “xxxxxxx”
}
$RegPath = ‘HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings’
$App = ‘{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe’
# Creating registry entries if they don’t exists
if (-NOT(Test-Path -Path “$RegPath\$App”)) {
New-Item -Path “$RegPath\$App” -Force
New-ItemProperty -Path “$RegPath\$App” -Name ‘ShowInActionCenter’ -Value 1 -PropertyType ‘DWORD’
}
# Make sure the app used with the action center is enabled
if ((Get-ItemProperty -Path “$RegPath\$App” -Name ‘ShowInActionCenter’ -ErrorAction SilentlyContinue).ShowInActionCenter -ne ‘1’) {
New-ItemProperty -Path “$RegPath\$App” -Name ‘ShowInActionCenter’ -Value 1 -PropertyType ‘DWORD’ -Force
}
If($Header_type -eq “GIF”)
{
$SCAGIF = “$env:temp\reboot.gif”
invoke-webrequest -Uri $URL -OutFile $SCAGIF -usebasicparsing
}
$Toast = @”
<toast scenario=”$Scenario”>
<visual>
<binding template=”ToastGeneric”>
<image placement=”hero” src=”$SCAGIF”/>
<image id=”1″ placement=”appLogoOverride” hint-crop=”circle” src=”$LogoImage”/>
<text placement=”attribution”>$AttributionText</text>
<text>$HeaderText</text>
<group>
<subgroup>
<text hint-style=”title” hint-wrap=”true” >$TitleText</text>
</subgroup>
</group>
<group>
<subgroup>
<text hint-style=”body” hint-wrap=”true” >$BodyText1</text>
</subgroup>
</group>
<group>
<subgroup>
<text hint-style=”body” hint-wrap=”true” >$BodyText2</text>
</subgroup>
</group>
<group>
<subgroup>
<text hint-style=”body” hint-wrap=”true” >$BodyText3</text>
<text hint-style=”body” hint-wrap=”true” >$BodyText4</text>
</subgroup>
</group>
</binding>
</visual>
<actions>
<action activationType=”system” arguments=”dismiss” content=”$DismissButtonContent”/>
</actions>
</toast>
“@
#Send the notification
Display-ToastNotification
}