{"id":395126,"date":"2024-12-18T14:45:28","date_gmt":"2024-12-18T14:45:28","guid":{"rendered":"https:\/\/www.ninjaone.com\/?post_type=script_hub&#038;p=395126"},"modified":"2024-12-18T14:45:48","modified_gmt":"2024-12-18T14:45:48","slug":"sende-snooze-benachrichtigung-powershell","status":"publish","type":"script_hub","link":"https:\/\/www.ninjaone.com\/de\/script-hub\/sende-snooze-benachrichtigung-powershell\/","title":{"rendered":"Senden von Snooze-Benachrichtigungen &#038; Abbruchbenachrichtigungen mit PowerShell"},"content":{"rendered":"<p>Senden von Snooze-Benachrichtigungen &amp; Abbruchbenachrichtigungen mit PowerShell<\/p>\n<p>Effiziente Kommunikation ist ein Eckpfeiler der IT-Verwaltung, insbesondere bei Managed Services und in Unternehmensumgebungen. Benachrichtigungen und Warnungen spielen eine entscheidende Rolle, um die Teams auf dem Laufenden zu halten und die Zuverl\u00e4ssigkeit des Systems zu gew\u00e4hrleisten. In diesem Blogbeitrag wird ein vielseitiges PowerShell-Skript vorgestellt, mit dem IT-Experten Toast-Benachrichtigungen mit anpassbaren Schlummer- und Beendigungsoptionen erstellen und senden k\u00f6nnen. Diese Funktionalit\u00e4t ist besonders n\u00fctzlich f\u00fcr Managed Service Provider (MSPs) und IT-Teams, die nach einfachen, benutzerfreundlichen M\u00f6glichkeiten suchen, um wichtige Nachrichten an Endbenutzer zu \u00fcbermitteln.<\/p>\n<p><strong>Kontext<\/strong><\/p>\n<p>In Windows 10 und dar\u00fcber hinaus sind Toast-Benachrichtigungen eine moderne M\u00f6glichkeit, Benutzer direkt im Betriebssystem zu benachrichtigen. Tools von Drittanbietern k\u00f6nnen zwar \u00e4hnliche Funktionen bieten, sind aber oft mit Lizenzkosten, unn\u00f6tigem Overhead oder eingeschr\u00e4nkter Anpassbarkeit verbunden. Dieses PowerShell-Skript bietet eine rationelle, kosteng\u00fcnstige Alternative, mit der IT-Experten auf die jeweiligen Bed\u00fcrfnisse zugeschnittene Snooze- und Entlassungsbenachrichtigungen erstellen k\u00f6nnen.<\/p>\n<p>MSPs und IT-Administratoren profitieren erheblich von diesem Tool. Ganz gleich, ob es darum geht, Benutzer an anstehende Aktualisierungen zu erinnern, sie \u00fcber kritische Ausf\u00e4lle zu benachrichtigen oder Statusaktualisierungen w\u00e4hrend der Systemwartung bereitzustellen \u2013 die M\u00f6glichkeit, umsetzbare Nachrichten zu \u00fcbermitteln, verbessert direkt die betriebliche Effizienz und das Engagement der Benutzer.<\/p>\n<p><strong>Das Skript zur Optimierung der Hintergrund-Verwaltung<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\">#Requires -Version 5.1\r\n\r\n&lt;#\r\n.SYNOPSIS\r\n    Sends a toast snooze\/dismiss notification to the currently signed in user. Please run as the Current Logged-on User. The script defaults to using NinjaOne's logo if none is provided.\r\n.DESCRIPTION\r\n    Sends a toast snooze\/dismiss notification to the currently signed in user. Please run as 'Current Logged on User'.\r\n    This defaults to using NinjaOne's logo in the Toast Message, but you can specify any png formatted image from a url.\r\n    You can also specify the \"ApplicationId\" to any string. The default is \"NinjaOne RMM\".\r\n\r\n    By using this script, you indicate your acceptance of the following legal terms as well as our Terms of Use at https:\/\/www.ninjaone.com\/terms-of-use.\r\n    Ownership Rights: NinjaOne owns and will continue to own all right, title, and interest in and to the script (including the copyright). NinjaOne is giving you a limited license to use the script in accordance with these legal terms. \r\n    Use Limitation: You may only use the script for your legitimate personal or internal business purposes, and you may not share the script with another party. \r\n    Republication Prohibition: Under no circumstances are you permitted to re-publish the script in any script library or website belonging to or under the control of any other software provider. \r\n    Warranty Disclaimer: The script is provided \u201cas is\u201d and \u201cas available\u201d, without warranty of any kind. NinjaOne makes no promise or guarantee that the script will be free from defects or that it will meet your specific needs or expectations. \r\n    Assumption of Risk: Your use of the script is at your own risk. You acknowledge that there are certain inherent risks in using the script, and you understand and assume each of those risks. \r\n    Waiver and Release: You will not hold NinjaOne responsible for any adverse or unintended consequences resulting from your use of the script, and you waive any legal or equitable rights or remedies you may have against NinjaOne relating to your use of the script. \r\n    EULA: If you are a NinjaOne customer, your use of the script is subject to the End User License Agreement applicable to you (EULA).\r\n\r\n.EXAMPLE\r\n    -Title \"My Title Here\" -Message \"My Message Here\"\r\n    Sends the title \"My Title Here\" and message \"My Message Here\" as a Toast message\/notification to the currently signed in user.\r\n.EXAMPLE\r\n    -Title \"My Title Here\" -Message \"My Message Here\" -ApplicationId \"MyCompany\"\r\n    Sends the title \"My Title Here\" and message \"My Message Here\" as a Toast message\/notification to the currently signed in user.\r\n        ApplicationId: Creates a registry entry for your toasts called \"MyCompany\".\r\n        PathToImageFile: Downloads a png image for the icon in the toast message\/notification.\r\n        SnoozeTimeOptionsInMinutes: Adds a dropdown to the toast message\/notification with options for snoozing the message.\r\n.OUTPUTS\r\n    None\r\n.NOTES\r\n    If you want to change the defaults then with in the param block.\r\n    ImagePath uses C:\\Users\\Public\\ as that is accessible by all users.\r\n    If you want to customize the application name to show your company name,\r\n        then look for $ApplicationId and change the content between the double quotes.\r\n\r\n    Minimum OS Architecture Supported: Windows 10 (IoT editions are not supported due to lack of shell)\r\n    Release Notes: Renamed script, Updated Script Variables\r\n#&gt;\r\n\r\n[CmdletBinding()]\r\nparam\r\n(\r\n    [string]$Title,\r\n    [string]$Message,\r\n    [string]$ApplicationId,\r\n    [string]$SnoozeTimeOptionsInMinutes,\r\n    [string]$PathToImageFile\r\n)\r\n\r\nbegin {\r\n    $Base64 = 'iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAMAAAD04JH5AAAAJFBMVEUARF0Apc0AmL8ApM0Aos0Aps7\/\/\/8Am8ia1ug9rtLd8\/jw+\/2tMDHwAAAABXRSTlMBrBTIcce4nvwAAAIeSURBVHic7dvrcoMgEAXgiOAivv\/7Fm+JBpCLwk7bsz86rcNkPw+Y0Gl5vd4lGtbLKSG7vmF18mwQnWpe3YcghP2Z1svU8OtbIOihm8op25M2gWBov9UqYJj\/vSRzAGsEkhMglxngWINbdbxLAAAAAAAAAAAAAKAI8Oz2KRtApPWThEyAbT8NZwDZGpeav6sLIKXNMBwAtuGotTGTvTpMRms9qkxEBsDe\/dz+A7B3rufeS\/utrCKPkAywzfYmK8BeOHY+lBkzBImALfwDgA4XnNLphCTA4e43AKmL9vNMJD8pCQAna20nP5D+SfkQgJyp1qS9PYsEKQDnpVP627WYJCgBmGj+GRmUAFIraSXWBAwDcwJJk1AXMIzcgHgElQHxCGoDohHcBsybgIvPpei70S2A0csuaNkTBRBTbA7uAOb271E0+gWxOSgHfG87yD+wGsCz7fGONNf9iwGTb89DnlkwkUVQCPD2t1sXz9A6gMDT5YsgsggKARljI\/vTMkDo7cU3B1USCL+oOwdVAMGF5RlcAxB+tBoBwq\/JDlDcAPYEAGgDuPiNBwkgASSABJAAEkACSAAJIAEkgASQABL4JwlcA9w\/9N4GTOZcl1OQMTgRoEannhv9O\/+PCAAAAAAAAAAAAACAPwhgP+7HeOCR1jOfjBHI9dBrz9W\/34\/d9jyHLvvPweP2GdCx\/3zyvLlAfZ8+l13LktJzAJ+nfgAP50EVLvPsRgAAAABJRU5ErkJggg=='\r\n    [string]$ImagePath = \"$($env:SystemDrive)\\Users\\Public\\PowerShellToastSnoozeImage.png\"\r\n\r\n    # Set the default ApplicationId if it's not provided. Use the Company Name if available, otherwise use the default.\r\n    $ApplicationId = if ($env:NINJA_COMPANY_NAME) { $env:NINJA_COMPANY_NAME } else { \"NinjaOne RMM\" }\r\n\r\n    Write-Host \"[Info] Using ApplicationId: $($ApplicationId -replace '\\s+','.')\"\r\n\r\n    if ($env:title -and $env:title -notlike \"null\") { $Title = $env:title }\r\n    if ($env:message -and $env:message -notlike \"null\") { $Message = $env:message }\r\n    if ($env:applicationId -and $env:applicationId -notlike \"null\") { $ApplicationId = $env:applicationId }\r\n    if ($env:pathToImageFile -and $env:pathToImageFile -notlike \"null\") { $PathToImageFile = $env:pathToImageFile }\r\n    if ($env:snoozeTimeOptionsInMinutes -and $env:snoozeTimeOptionsInMinutes -notlike \"null\") { $SnoozeTimeOptionsInMinutes = $env:snoozeTimeOptionsInMinutes }\r\n\r\n    if ([String]::IsNullOrWhiteSpace($Title)) {\r\n        Write-Host \"[Error] A Title is required.\"\r\n        exit 1\r\n    }\r\n    if ([String]::IsNullOrWhiteSpace($Message)) {\r\n        Write-Host \"[Error] A Message is required.\"\r\n        exit 1\r\n    }\r\n\r\n    if ($Title.Length -gt 82) {\r\n        Write-Host \"[Warn] The Title is longer than 82 characters. The title will be truncated by the Windows API to 82 characters.\"\r\n    }\r\n    if ($Message.Length -gt 160) {\r\n        Write-Host \"[Warn] The Message is longer than 160 characters. The message might get truncated by the Windows API.\"\r\n    }\r\n\r\n    function Test-IsSystem {\r\n        $id = [System.Security.Principal.WindowsIdentity]::GetCurrent()\r\n        return $id.Name -like \"NT AUTHORITY*\" -or $id.IsSystem\r\n    }\r\n\r\n    if (Test-IsSystem) {\r\n        Write-Host \"[Error] Please run this script as 'Current Logged on User'.\"\r\n        Exit 1\r\n    }\r\n\r\n    function Set-RegKey {\r\n        param (\r\n            $Path,\r\n            $Name,\r\n            $Value,\r\n            [ValidateSet(\"DWord\", \"QWord\", \"String\", \"ExpandedString\", \"Binary\", \"MultiString\", \"Unknown\")]\r\n            $PropertyType = \"DWord\"\r\n        )\r\n        if (-not $(Test-Path -Path $Path)) {\r\n            # Check if path does not exist and create the path\r\n            New-Item -Path $Path -Force | Out-Null\r\n        }\r\n        if ((Get-ItemProperty -Path $Path -Name $Name -ErrorAction Ignore)) {\r\n            # Update property and print out what it was changed from and changed to\r\n            $CurrentValue = (Get-ItemProperty -Path $Path -Name $Name -ErrorAction Ignore).$Name\r\n            try {\r\n                Set-ItemProperty -Path $Path -Name $Name -Value $Value -Force -Confirm:$false -ErrorAction Stop | Out-Null\r\n            }\r\n            catch {\r\n                Write-Host \"[Error] Unable to Set registry key for $Name please see below error!\"\r\n                Write-Host $_.Exception.Message\r\n                exit 1\r\n            }\r\n            Write-Host \"[Info] $Path\\$Name changed from:\"\r\n            Write-Host \" $CurrentValue to:\"\r\n            Write-Host \" $($(Get-ItemProperty -Path $Path -Name $Name -ErrorAction Ignore).$Name)\"\r\n        }\r\n        else {\r\n            # Create property with value\r\n            try {\r\n                New-ItemProperty -Path $Path -Name $Name -Value $Value -PropertyType $PropertyType -Force -Confirm:$false -ErrorAction Stop | Out-Null\r\n            }\r\n            catch {\r\n                Write-Host \"[Error] Unable to Set registry key for $Name please see below error!\"\r\n                Write-Host $_.Exception.Message\r\n                exit 1\r\n            }\r\n            Write-Host \"[Info] Set $Path\\$Name to:\"\r\n            Write-Host \" $($(Get-ItemProperty -Path $Path -Name $Name -ErrorAction Ignore).$Name)\"\r\n        }\r\n    }\r\n\r\n    function ConvertFrom-Base64 {\r\n        param(\r\n            $Base64,\r\n            $Path\r\n        )\r\n        $bytes = [Convert]::FromBase64String($Base64)\r\n\r\n        $ErrorActionPreference = [System.Management.Automation.ActionPreference]::SilentlyContinue\r\n        [IO.File]::WriteAllBytes($Path, $bytes)\r\n        $ErrorActionPreference = [System.Management.Automation.ActionPreference]::Continue\r\n    }\r\n\r\n    # Utility function for downloading files.\r\n    function Invoke-Download {\r\n        param(\r\n            [Parameter()]\r\n            [String]$URL,\r\n            [Parameter()]\r\n            [String]$Path,\r\n            [Parameter()]\r\n            [int]$Attempts = 3,\r\n            [Parameter()]\r\n            [Switch]$SkipSleep\r\n        )\r\n        Write-Host \"[Info] Used $PathToImageFile for the image and saving to $ImagePath\"\r\n\r\n        $SupportedTLSversions = [enum]::GetValues('Net.SecurityProtocolType')\r\n        if ( ($SupportedTLSversions -contains 'Tls13') -and ($SupportedTLSversions -contains 'Tls12') ) {\r\n            [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol::Tls13 -bor [System.Net.SecurityProtocolType]::Tls12\r\n        }\r\n        elseif ( $SupportedTLSversions -contains 'Tls12' ) {\r\n            [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12\r\n        }\r\n        else {\r\n            # Not everything requires TLS 1.2, but we'll try anyways.\r\n            Write-Host \"[Warn] TLS 1.2 and or TLS 1.3 isn't supported on this system. This download may fail!\"\r\n            if ($PSVersionTable.PSVersion.Major -lt 3) {\r\n                Write-Host \"[Warn] PowerShell 2 \/ .NET 2.0 doesn't support TLS 1.2.\"\r\n            }\r\n        }\r\n\r\n        $i = 1\r\n        While ($i -le $Attempts) {\r\n            # Some cloud services have rate-limiting\r\n            if (-not ($SkipSleep)) {\r\n                $SleepTime = Get-Random -Minimum 1 -Maximum 7\r\n                Write-Host \"[Info] Waiting for $SleepTime seconds.\"\r\n                Start-Sleep -Seconds $SleepTime\r\n            }\r\n            if ($i -ne 1) { Write-Host \"\" }\r\n            Write-Host \"[Info] Download Attempt $i\"\r\n\r\n            $PreviousProgressPreference = $ProgressPreference\r\n            $ProgressPreference = 'SilentlyContinue'\r\n            try {\r\n                # Invoke-WebRequest is preferred because it supports links that redirect, e.g., https:\/\/t.ly\r\n                # Standard options\r\n                $WebRequestArgs = @{\r\n                    Uri                = $URL\r\n                    MaximumRedirection = 10\r\n                    UseBasicParsing    = $true\r\n                    OutFile            = $Path\r\n                }\r\n\r\n                # Download The File\r\n                Invoke-WebRequest @WebRequestArgs\r\n\r\n                $ProgressPreference = $PreviousProgressPreference\r\n                $File = Test-Path -Path $Path -ErrorAction SilentlyContinue\r\n            }\r\n            catch {\r\n                Write-Host \"[Error] An error has occurred while downloading!\"\r\n                Write-Warning $_.Exception.Message\r\n\r\n                if (Test-Path -Path $Path -ErrorAction SilentlyContinue) {\r\n                    Remove-Item $Path -Force -Confirm:$false -ErrorAction SilentlyContinue\r\n                }\r\n\r\n                $File = $False\r\n            }\r\n\r\n            if ($File) {\r\n                $i = $Attempts\r\n            }\r\n            else {\r\n                Write-Host \"[Error] File failed to download.\"\r\n                Write-Host \"\"\r\n            }\r\n\r\n            $i++\r\n        }\r\n\r\n        if (-not (Test-Path $Path)) {\r\n            Write-Host \"[Error] Failed to download file!\"\r\n            exit 1\r\n        }\r\n        else {\r\n            return $Path\r\n        }\r\n    }\r\n\r\n    function Show-Notification {\r\n        [CmdletBinding()]\r\n        Param (\r\n            [string]\r\n            $ApplicationId,\r\n            [string]\r\n            $ToastTitle,\r\n            [string]\r\n            [Parameter(ValueFromPipeline)]\r\n            $ToastText,\r\n            [string]\r\n            $SnoozeOptions\r\n        )\r\n\r\n        # Import all the needed libraries\r\n        [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] &gt; $null\r\n        [Windows.UI.Notifications.ToastNotification, Windows.UI.Notifications, ContentType = WindowsRuntime] &gt; $null\r\n        [Windows.System.User, Windows.System, ContentType = WindowsRuntime] &gt; $null\r\n        [Windows.System.UserType, Windows.System, ContentType = WindowsRuntime] &gt; $null\r\n        [Windows.System.UserAuthenticationStatus, Windows.System, ContentType = WindowsRuntime] &gt; $null\r\n        [Windows.Storage.ApplicationData, Windows.Storage, ContentType = WindowsRuntime] &gt; $null\r\n\r\n        # Make sure that we can use the toast manager, also checks if the service is running and responding\r\n        try {\r\n            $ToastNotifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier(\"$ApplicationId\")\r\n        }\r\n        catch {\r\n            Write-Host $_.Exception.Message\r\n            Write-Host \"[Error] Failed to create notification.\"\r\n        }\r\n\r\n        # Create the xml for the snooze options\r\n        $IsFirst = $true\r\n        if ($($SnoozeOptions -split ',').Count -gt 5) {\r\n            Write-Host \"[Error] Too many snooze options provided. Maximum is 5.\"\r\n            exit 1\r\n        }\r\n        $SnoozeXml = $SnoozeOptions -split ',' | ForEach-Object {\r\n            # Trim whitespace\r\n            $Option = \"$_\".Trim()\r\n            if ($IsFirst) {\r\n                # Add the input and default selection\r\n                \"&lt;input id='snoozeTime' type='selection' defaultInput='$Option'&gt;\"\r\n                $IsFirst = $false\r\n            }\r\n            # Check if the option is a number\r\n            if ([int]::TryParse($Option, [ref]$null)) {\r\n                # Convert the number to an integer\r\n                $Option = [int]$Option\r\n            }\r\n            else {\r\n                # If not a number, exit with an error\r\n                Write-Host \"[Error] Invalid snooze time option '$Option' provided.\"\r\n                exit 1\r\n            }\r\n            # Add the selection\r\n            if ($Option -ge 60) {\r\n                # Get the number of hours and minutes\r\n                # Round the number of hours to the nearest hour\r\n                $Hours = [math]::Round($Option \/ 60, 0)\r\n                # Get the number of minutes\r\n                $MinutesMod = $Option % 60\r\n                # Format the number of minutes\r\n                $Minutes = if ($MinutesMod -eq 0) {\r\n                    # If the number of minutes is 0, don't display anything\r\n                    \"\"\r\n                }\r\n                elseif ($MinutesMod -gt 1) {\r\n                    # If the number of minutes is greater than 1, format it as ' 2 Minutes'\r\n                    \" $MinutesMod Minutes\"\r\n                }\r\n                elseif ($MinutesMod -eq 1) {\r\n                    # If the number of minutes is 1, format it as ' 1 Minute'\r\n                    \" $MinutesMod Minute\"\r\n                }\r\n                # Format the number of hours\r\n                $Unit = if ($Hours -gt 1) { 'Hours' }else { 'Hour' }\r\n                \"&lt;selection id='$($Option)' content='$($Hours) $($Unit)$($Minutes)'\/&gt;\"\r\n            }\r\n            elseif ($Option -lt 60) {\r\n                # Format the number of minutes when it's less than 60 minutes\r\n                $Minutes = $Option\r\n                $Unit = if ($Minutes -gt 1) { 'Minutes' }else { 'Minute' }\r\n                \"&lt;selection id='$($Option)' content='$($Minutes) $($Unit)'\/&gt;\"\r\n            }\r\n        }\r\n\r\n        # Create a new toast notification\r\n        $RawXml = [xml] @\"\r\n&lt;toast&gt;\r\n    &lt;visual&gt;\r\n        &lt;binding template='ToastGeneric'&gt;\r\n            &lt;image placement='appLogoOverride' src='$ImagePath'\/&gt;\r\n            &lt;text id='1'&gt;$ToastTitle&lt;\/text&gt;\r\n            &lt;text id='2'&gt;$ToastText&lt;\/text&gt;\r\n        &lt;\/binding&gt;\r\n    &lt;\/visual&gt;\r\n    &lt;actions&gt;\r\n        $SnoozeXml\r\n        &lt;\/input&gt;\r\n        &lt;action activationType=\"system\" arguments=\"snooze\" hint-inputId=\"snoozeTime\" content=\"\" \/&gt;\r\n        &lt;action activationType=\"system\" arguments=\"dismiss\" content=\"\"\/&gt;\r\n    &lt;\/actions&gt;\r\n&lt;\/toast&gt;\r\n\"@\r\n\r\n        # Serialized Xml for later consumption\r\n        $SerializedXml = New-Object Windows.Data.Xml.Dom.XmlDocument\r\n        $SerializedXml.LoadXml($RawXml.OuterXml)\r\n\r\n        # Setup how are toast will act, such as expiration time\r\n        $Toast = $null\r\n        $Toast = [Windows.UI.Notifications.ToastNotification]::new($SerializedXml)\r\n        $Toast.Tag = \"PowerShell\"\r\n        $Toast.Group = \"PowerShell\"\r\n\r\n        # Show our message to the user\r\n        $ToastNotifier.Show($Toast)\r\n    }\r\n}\r\nprocess {\r\n    Write-Host \"ApplicationID: $ApplicationId\"\r\n\r\n    if (-not $(Split-Path -Path $ImagePath -Parent | Test-Path -ErrorAction SilentlyContinue)) {\r\n        try {\r\n            New-Item \"$(Split-Path -Path $ImagePath -Parent)\" -ItemType Directory -ErrorAction Stop\r\n            Write-Host \"[Info] Created folder: $(Split-Path -Path $ImagePath -Parent)\"\r\n        }\r\n        catch {\r\n            Write-Host \"[Error] Failed to create folder: $(Split-Path -Path $ImagePath -Parent)\"\r\n            exit 1\r\n        }\r\n    }\r\n\r\n    $DownloadArguments = @{\r\n        URL  = $PathToImageFile\r\n        Path = $ImagePath\r\n    }\r\n\r\n    Set-RegKey -Path \"HKCU:\\SOFTWARE\\Classes\\AppUserModelId\\$($ApplicationId -replace '\\s+','.')\" -Name \"DisplayName\" -Value $ApplicationId -PropertyType String\r\n    if ($PathToImageFile -like \"http*\") {\r\n        Invoke-Download @DownloadArguments\r\n    }\r\n    elseif ($PathToImageFile -match \"^[a-zA-Z]:\\\\\" -and $(Test-Path -Path $PathToImageFile -ErrorAction SilentlyContinue)) {\r\n        Write-Host \"[Info] Image is a local file, copying to $ImagePath\"\r\n        Copy-Item -Path $PathToImageFile -Destination $ImagePath\r\n    }\r\n    elseif ($PathToImageFile -match \"^[a-zA-Z]:\\\\\" -and -not $(Test-Path -Path $PathToImageFile -ErrorAction SilentlyContinue)) {\r\n        Write-Host \"[Error] Image does not exist at $PathToImageFile\"\r\n        exit 1\r\n    }\r\n    else {\r\n        Write-Host \"[Info] No image given, converting base64 on line 43 and saving to $ImagePath.\"\r\n        Write-Host \"[Info] Image will be used for the toast message.\"\r\n        ConvertFrom-Base64 -Base64 $Base64 -Path $ImagePath\r\n    }\r\n\r\n    Set-RegKey -Path \"HKCU:\\SOFTWARE\\Classes\\AppUserModelId\\$($ApplicationId -replace '\\s+','.')\" -Name \"IconUri\" -Value \"$ImagePath\" -PropertyType String\r\n\r\n    Write-Host \"[Info] System is ready to send Toast Messages to the currently logged on user.\"\r\n\r\n    try {\r\n        Write-Host \"[Info] Attempting to send message to user...\"\r\n        $NotificationParams = @{\r\n            ToastTitle    = $Title\r\n            ToastText     = $Message\r\n            ApplicationId = \"$($ApplicationId -replace '\\s+','.')\"\r\n            SnoozeOptions = $SnoozeTimeOptionsInMinutes\r\n        }\r\n        Show-Notification @NotificationParams -ErrorAction Stop\r\n        Write-Host \"[Info] Message sent to user.\"\r\n    }\r\n    catch {\r\n        Write-Host \"[Error] Failed to send message to user.\"\r\n        Write-Host $_.Exception.Message\r\n        exit 1\r\n    }\r\n    exit 0\r\n}\r\nend {\r\n    \r\n    \r\n    \r\n}<\/pre>\n<p>&nbsp;<\/p>\n\n<div class=\"in-context-cta\"><p>Sparen Sie Zeit mit \u00fcber 300+ Skripten aus dem NinjaOne Dojo.<\/p>\n<p>\u2192 <a class=\"waffle-rich-text-link\" href=\"https:\/\/www.ninjaone.com\/freetrialform\/\">Erhalten Sie noch heute Zugang<\/a>.<\/p>\n<\/div>\n<p><strong>Detailansicht<\/strong><\/p>\n<p>Das mitgelieferte PowerShell-Skript enth\u00e4lt mehrere Schl\u00fcsselkomponenten, die auf Flexibilit\u00e4t und Funktionalit\u00e4t ausgelegt sind. Im Folgenden wird Schritt f\u00fcr Schritt erkl\u00e4rt, wie es funktioniert:<\/p>\n<ol>\n<li><strong>Initialisierung und Parameter<\/strong><br \/>\nDas Skript akzeptiert Parameter f\u00fcr den Titel der Benachrichtigung, die Nachricht, die Anwendungs-ID, die Snooze-Optionen und einen optionalen Pfad f\u00fcr die Bilddatei. Es validiert Eingaben und setzt Standardwerte, wenn keine Parameter angegeben werden. Die Standardanwendungskennung lautet beispielsweise &#8222;NinjaOne RMM&#8220;, um die Konsistenz der Identifizierung im Windows-Benachrichtigungscenter zu gew\u00e4hrleisten.<\/li>\n<li><strong>Benutzer-Validierung<\/strong><br \/>\nDas Skript pr\u00fcft, ob es als der &#8222;aktuell angemeldete Benutzer&#8220; ausgef\u00fchrt wird. Dies stellt sicher, dass die Benachrichtigungen den richtigen Empf\u00e4nger erreichen, anstatt in einem erh\u00f6hten Systemkontext zu laufen, wo Toast-Benachrichtigungen nicht unterst\u00fctzt werden.<\/li>\n<li><strong>Konfiguration der Registry<\/strong><br \/>\nMit der Funktion <code>Set-RegKey<\/code> erstellt oder aktualisiert das Skript Registrierungseintr\u00e4ge, um die Anwendung korrekt im Windows-Benachrichtigungscenter zu registrieren und ein benutzerdefiniertes Symbol mit der Benachrichtigung zu verkn\u00fcpfen.<\/li>\n<li><strong>Bildbearbeitung<\/strong><br \/>\nBenachrichtigungen k\u00f6nnen ein benutzerdefiniertes Bild enthalten. Das Skript unterst\u00fctzt drei Szenarien:<\/p>\n<ul>\n<li>Eine URL zum Herunterladen eines Bildes.<\/li>\n<li>Ein lokaler Dateipfad zum Kopieren.<\/li>\n<li>Ein standardm\u00e4\u00dfiges, mit base64 kodiertes NinjaOne-Logo, das konvertiert und als Bilddatei gespeichert wird, wenn kein benutzerdefiniertes Bild angegeben wird.<\/li>\n<\/ul>\n<\/li>\n<li><strong>Generierung von XML-Benachrichtigungen<\/strong><br \/>\nDas Skript generiert XML-Code, der die Struktur der Toastnachricht definiert, einschlie\u00dflich Titel, Text, Bild und Snooze-Optionen. Die Funktion <code>Show-Notification<\/code> verwendet die Windows Runtime API, um die Toast-Benachrichtigung anzuzeigen.<\/li>\n<li><strong>Snooze- und Entlassungsfunktionalit\u00e4t<\/strong><br \/>\nDie Benutzer k\u00f6nnen Benachrichtigungen f\u00fcr eine vorher festgelegte Zeitspanne in den Schlummermodus versetzen oder sie ganz abschalten. Diese Optionen sind in der XML-Datei definiert und erm\u00f6glichen die Interaktion mit dem Benutzer direkt in der Meldung.<\/li>\n<\/ol>\n<p><strong>Potenzielle Anwendungsf\u00e4lle<\/strong><\/p>\n<p><em>Fallstudie: System-Update-Benachrichtigungen<\/em><\/p>\n<p>Stellen Sie sich einen IT-Administrator in einer Unternehmensumgebung vor, der \u00fcber Nacht eine wichtige Systemaktualisierung durchf\u00fchren m\u00f6chte. Um sicherzustellen, dass die Benutzer informiert sind, verwenden sie dieses Skript, um eine Toast-Benachrichtigung mit dem Titel &#8222;System Maintenance Notification&#8220; (Systemwartungsbenachrichtigung) mit der Nachricht &#8222;Ihr System wird um 2:00 Uhr morgens f\u00fcr Updates neu gestartet&#8220; zu senden. Klicken Sie auf Schlummern oder Ablehnen.<\/p>\n<p><strong>Anpassungsm\u00f6glichkeiten:<\/strong> Die Meldung enth\u00e4lt das Logo der Organisation.<br \/>\n<strong>Snooze-Optionen:<\/strong> Die Benutzer k\u00f6nnen die Erinnerung um 15, 30 oder 60 Minuten verz\u00f6gern.<br \/>\n<strong>Das Ergebnis:<\/strong> Das Team sorgt daf\u00fcr, dass die Nutzer gut informiert sind, ohne dass sie manuell nachfassen m\u00fcssen.<\/p>\n<p><strong>Vergleiche<\/strong><\/p>\n<p><em>Alternative Methoden:<\/em><\/p>\n<ul>\n<li><strong>Benachrichtigungstools von Drittanbietern:<\/strong> Sie sind zwar robust, aber es fehlt ihnen m\u00f6glicherweise an Integrationsm\u00f6glichkeiten und sie sind mit Kosten verbunden.<\/li>\n<li><strong>Eingebaute Windows-Gruppenrichtlinien-Benachrichtigungen:<\/strong> Begrenzte Anpassungsm\u00f6glichkeiten und keine Snooze-Funktion.<\/li>\n<\/ul>\n<p>Im Vergleich zu diesen Methoden bietet dieses PowerShell-Skript:<\/p>\n<ul>\n<li>Gr\u00f6\u00dfere Anpassungsm\u00f6glichkeiten mit Bildunterst\u00fctzung.<\/li>\n<li>Verbesserte Benutzerfreundlichkeit mit Schlummer-\/Abschaltoptionen.<\/li>\n<li>Kosteneffizienz, Nutzung der nativen Windows-APIs.<\/li>\n<\/ul>\n<p><strong>FAQs<\/strong><\/p>\n<p><strong>F: Kann das Skript als Administrator ausgef\u00fchrt werden?<\/strong><br \/>\nNein, es muss als der aktuell angemeldete Benutzer ausgef\u00fchrt werden, damit die Benachrichtigungen richtig angezeigt werden.<\/p>\n<p><strong>F: Was geschieht, wenn kein Bild zur Verf\u00fcgung gestellt wird?<\/strong><br \/>\nEs wird ein Standard-NinjaOne-Logo verwendet, das sicherstellt, dass jede Benachrichtigung mit einem Markenzeichen versehen ist.<\/p>\n<p><strong>F: Wie werden die Schlummeroptionen konfiguriert?<\/strong><br \/>\nSchlummerzeiten werden als kommagetrennte Liste definiert (z. B. &#8222;15,30,60&#8220; f\u00fcr 15, 30 und 60 Minuten).<\/p>\n<p><strong>F: Ist dies mit den Windows IoT-Editionen kompatibel?<\/strong><br \/>\nNein, da es in den IoT-Editionen keine H\u00fclle gibt.<\/p>\n<p><strong>Folgen<\/strong><\/p>\n<p>Mithilfe dieses Skripts k\u00f6nnen IT-Teams die Zustellung von Benachrichtigungen standardisieren und so sicherstellen, dass die Nachrichten verwertbar und relevant sind. In gr\u00f6\u00dferen Umgebungen verbessert dies die Aufmerksamkeit der Benutzer und reduziert Ausfallzeiten, die durch verpasste Warnmeldungen verursacht werden. Dar\u00fcber hinaus helfen die Branding-Optionen den MSPs, ihre Identit\u00e4t zu st\u00e4rken und gleichzeitig ihre Professionalit\u00e4t zu wahren.<\/p>\n<p><strong>Empfehlungen<\/strong><\/p>\n<ul>\n<li><strong>Test in einer Nicht-Produktionsumgebung:<\/strong> \u00dcberpr\u00fcfen Sie das Verhalten des Skripts in einer kontrollierten Umgebung, bevor Sie es umfassend einsetzen.<\/li>\n<li><strong>Anpassen der Anwendungs-IDs:<\/strong> Verwenden Sie organisationsspezifische Identifikatoren f\u00fcr eine bessere Verwaltung und Sichtbarkeit.<\/li>\n<li><strong>Benutzer-Feedback \u00fcberwachen:<\/strong> Sammeln Sie Anregungen, um die Schlummeroptionen und den Inhalt der Benachrichtigungen zu verfeinern, damit die Nutzer m\u00f6glichst aktiv werden.<\/li>\n<\/ul>\n<p><strong>Abschlie\u00dfende \u00dcberlegungen<\/strong><\/p>\n<p>Dieses Skript ist ein Beispiel daf\u00fcr, wie NinjaOne und \u00e4hnliche IT-Management-L\u00f6sungen IT-Experten unterst\u00fctzen k\u00f6nnen. Durch die Kombination von Einfachheit und fortschrittlicher Anpassung erm\u00f6glicht das Skript eine effiziente Kommunikation und verbessert die Benutzerfreundlichkeit. Unabh\u00e4ngig davon, ob Sie ein MSP oder ein internes IT-Team sind, entspricht die Nutzung von Tools wie diesem den Best Practices f\u00fcr das IT-Betriebsmanagement.<\/p>\n<p>F\u00fcr ma\u00dfgeschneiderte L\u00f6sungen bietet NinjaOne eine Reihe von Tools, die IT-Workflows rationalisieren und die Systemzuverl\u00e4ssigkeit optimieren.<\/p>\n","protected":false},"author":35,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_acf_changed":false,"_relevanssi_hide_post":"","_relevanssi_hide_content":"","_relevanssi_pin_for_all":"","_relevanssi_pin_keywords":"","_relevanssi_unpin_keywords":"","_relevanssi_related_keywords":"","_relevanssi_related_include_ids":"","_relevanssi_related_exclude_ids":"","_relevanssi_related_no_append":"","_relevanssi_related_not_related":"","_relevanssi_related_posts":"","_relevanssi_noindex_reason":"","_lmt_disableupdate":"no","_lmt_disable":""},"operating_system":[4212],"use_cases":[4309],"class_list":["post-395126","script_hub","type-script_hub","status-publish","hentry","script_hub_category-windows"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/script_hub\/395126","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/script_hub"}],"about":[{"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/types\/script_hub"}],"author":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/comments?post=395126"}],"wp:attachment":[{"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/media?parent=395126"}],"wp:term":[{"taxonomy":"script_hub_category","embeddable":true,"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/operating_system?post=395126"},{"taxonomy":"use_cases","embeddable":true,"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/use_cases?post=395126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}