Skip to main content

Toast Notification

Summary

This task is to create and manage toast notifications with customizable options, including images, buttons, and scenarios for different use cases. It is CW RMM implementation of the agnostic script Invoke-ToastNotification.ps1.

Update Notice: 2025-07-22

  • A script can be triggered via a button click within the notification.
  • The dismiss button is optional and can be excluded.
  • Notifications can be shown with or without buttons.
  • New Parameters:
    • RunScriptButton
    • RunScriptButtonText
    • ScriptPath
    • ScriptContext
    • ScriptStyle
    • HideDismissButton

Sample Run

Image1

Parameters

IDNameValue
1NotificationTypeGeneric
2RebootButton1
3RunScriptButton1
4RunScriptButtonTextReboot at 8
5ScriptPathC:\ProgramData_Automation\Script\Rebootat8\Rebootat8.ps1
6ScriptContextSystem
7ScriptStyleHidden
8LearnMoreButton1
9LearnMoreUrlhttps://en.wikipedia.org/wiki/Hamster
10HideDismissButton1
11TitleTextHamster Overload Detected!
12AttributionTextwww.provaltech.com
13BodyText1The tiny hamster powering your computer is absolutely exhausted and needs a magical nap to keep things running smoothly! Please be kind, click ''Reboot Now'' to give it a break, or choose ''Reboot at 8'' to let it rest later tonight.
14BodyText2If you ignore this plea, the hamster will take matters into its own tiny paws and force a nap at 8 PM anyway. Let''s not push our luck with a tired rodent on a wheel!.
15LogoImageC:\ProgramData_Automation\Script\Rebootat8\magicalHamster.png
16HeroImageC:\ProgramData_Automation\Script\Rebootat8\runningHamster.png
17NotificationAppNameWheelWorks
18RepeatOnce
19MaxOccurrences1

Outcome

Notification

Image1

Scheduled Task

Image2

Reboot at 8

Image2

Affected Areas on Prompt Based on Example Variables

Image3

Dependencies

Invoke-ToastNotification

User Parameters

ParameterExampleAccepted ValuesRequiredDefaultTypeDescription
NotificationTypeGeneric
  • Generic
  • PendingRebootUptime
  • PendingRebootCheck
  • ADPasswordExpiration
TrueTextThe type of notification to send. The accepted values for NotificationType are generic, PendingRebootUptime, PendingRebootCheck, and ADPasswordExpiration. It is a mandatory variable.
  • Generic: Enables a static, generic toast notification.
  • PendingRebootUptime: Displays a toast notification reminding users to restart their system after exceeding the maximum uptime.
  • PendingRebootCheck: Displays a toast notification when a pending reboot is detected through the system registry or WMI.
  • ADPasswordExpiration: Sends a toast notification to users when their Active Directory password is nearing expiration.
RunScriptButtonMarkedFalseFalseFlagSet RunScriptButton to 1 to enable the 'Run Script' button in the notification. To disable it, either set the value to 0 or remove the variable. Please note that enabling this button will automatically disable the 'Snooze' button.
RunScriptButtonTextScript NameFalseRunScriptTextSet the string in the RunScriptButtonText variable to customize the text of the RunScript button. Delete the variable or leave it blank to fall back to the default value. The default is RunScript. RunScriptButton should be enabled or set to 1 to enable the RunScriptButtonText variable.
ScriptPathC:\Temp\ScriptName.ps1True (when RunScriptButton is Enabled)TextScriptPath specifies the full path to a PowerShell script (.ps1) that will be executed when the 'RunScript' button is clicked. This must be a valid path ending in .ps1. Setting this variable is mandatory if RunScriptButton is enabled. If RebootScriptButton is not enabled, this variable can be omitted by leaving it blank or removing it entirely.
ScriptContextSystem
  • User
  • System
FalseUserTextScriptContext Specifies the context in which the custom script should be executed when triggered from the notification on clicking the 'RunScript' button. Valid values are 'User' (runs in the current user context) or 'System' (runs with elevated/system privileges, if supported). Default is 'User'. RunScriptButton should be enabled to use the ScriptContext variable.
ScriptStyleHidden
  • Hidden
  • Interactive
FalseHiddenTextScriptStyle defines how the script should be executed when the 'RunScript' button is clicked. Valid options are 'Interactive' (displays messages or launches installers on the user's desktop) and 'Hidden' (runs silently in the background). The default value is 'Hidden'. This variable is only applicable if RunScriptButton is enabled.
RebootButtonUnmarkedFalseFalseFlagSelect it to enable the Reboot button in the notification. RebootButton is available for Generic, PendingRebootUptime, and PendingRebootCheck notification types.
LearnMoreButtonUnmarkedFalseFalseFlagSelect it to enable the Learn More button in the notification.
LearnMoreUrlhttps://www.provaltech.comFalseTextSet the URL to navigate by clicking the Learn More button in the notification. LearnMoreButton should be selected to allow the LearnMoreUrl parameter.
SnoozeButtonUnmarkedFalseFalseFlagSelect it to enable the Snooze button in the notification.

Note: The LearnMoreButton and the SnoozeButton cannot be enabled simultaneously.
DismissButtonTextDismissFalseDismissTextCustomizes the text of the dismiss button. Default is "Dismiss."
TitleTextReboot RequiredTrueTextSets the title of the notification. It is mandatory to set this parameter.
AttributionTexthttps://www.provaltech.comTrueTextDisplays attribution text, such as a company name or website, for authenticity. If left blank, the task will use the client name of the agent in attribution text.
BodyText1An application is installed on your computer and it is required to reboot the machine ASAP.TrueTextThe main text content of the notification body. It is mandatory to set this parameter.
BodyText2Ignoring the notification is not suggestedFalseTextSecondary text content is displayed below BodyText1.
LogoImagehttps://labtech.provaltech.com/labtech/transfer/images/alogo.jpgFalseTextSpecify the URL or path for the logo image in the notification. For best experience, keep the ratio 1:1 (Horizontal:Vertical) ; Example - 300px:300px (Horizontal:Vertical)
HeroImagehttps://labtech.provaltech.com/labtech/transfer/images/alogo.jpgFalseTextSpecify the URL or path for the hero image displayed at the top of the notification. For best experience, keep the ratio 2:1 (Horizontal:Vertical); Example - 600px:300px (Horizontal:Vertical)
Deadline2025-02-05 08:00:00yyyy-MM-dd HH:mm:ssFalseCurrent +14daysTextSets the deadline for the notification. Format: yyyy-MM-dd HH:mm:ss. Note that RunScriptButton and Deadline cannot be enabled at the same time. Additionally, enabling RunScriptButton will automatically disable Deadline.
MaxUptimeDays30False30NumberValueDefines the maximum uptime (in days) for the PendingRebootUptime NotificationType parameter. Default is 30 days.
ADPasswordExpirationDays7False7NumberValueNumber of days before password expiration when reminders should start. It is available for the ADPasswordExpiration NotificationType parameter. Default is 7 days.
RepeatOnceOnce, Hourly, XXMinutes, XXHours, Daily, XXDays.FalseOnceTextSpecifies how frequently the notification should repeat. Options: Once, Hourly, XXMinutes, XXHours, Daily, XXDays.
NotificationAppNameConnectwise RMMFalseWindows PowerShellTextSpecifies the name of the application that will display the notification.
MaxOccurrences5FalseNumber ValuesSpecifies the maximum number of notifications to send before the scheduled task is automatically removed. This works in conjunction with the Repeat parameter, except when Repeat is set to Once.

NOTE: For All String Parameters (Specifically for TitleText, BodyText1, and BodyText2)
Keep the message under 300 characters.
Avoid using single quotations within the message. If it's necessary, then escape the quotation with another one.

Example:
user's --> Incorrect
user''s --> correct

Task Creation

Script Details

Create a new Script Editor style script in the system to implement this Task.

Image3

Image4

Name: Toast Notification

Description: A script to create and manage toast notifications with customizable options, including images, buttons, and scenarios for different use cases.

Category: custom

Image5

Parameters

NotificationType

Add a new parameter by clicking the Add Parameter button present at the top-right corner of the screen.

AddParameter

This screen will appear. 

ParameterScreen

  • Set NotificationType in the Parameter Name field.

  • Select Text String from the Parameter Type dropdown menu.

  • Toggle Required Field.

  • Click the Save button.

Parameter1

It will ask for the confirmation to proceed. Click the Confirm button to create the parameter.

Confirmation

RebootButton

Add another parameter by clicking the Add Parameter button present at the top-right corner of the screen.

AddParameter

  • Set RebootButton in the Parameter Name field.

  • Select Flag from the Parameter Type dropdown menu.

  • Set Default Value as False.

  • Click the Save button.

  • Click the Confirm button to create the parameter.

Parameter2

LearnMoreButton

Add another parameter by clicking the Add Parameter button present at the top-right corner of the screen.

AddParameter

  • Set LearnMoreButton in the Parameter Name Field.

  • Select Flag from the Parameter Type dropdown menu.

  • Set Default Value as False.

  • Click the Save button.

  • Click the Confirm button to create the parameter.

Parameter3

LearnMoreUrl

Add another parameter by clicking the Add Parameter button present at the top-right corner of the screen.

AddParameter

  • Set LearnMoreUrl in the Parameter Name field.

  • Select Text String from the Parameter Type dropdown menu.

  • Click the Save button.

  • Click the Confirm button to create the parameter.

Parameter4

SnoozeButton

Add another parameter by clicking the Add Parameter button present at the top-right corner of the screen.

AddParameter

  • Set SnoozeButton in the Parameter Name Field.

  • Select Flag from the Parameter Type dropdown menu.

  • Set Default Value as False.

  • Click the Save button.

  • Click the Confirm button to create the parameter.

Parameter5

DismissButtonText

Add another parameter by clicking the Add Parameter button present at the top-right corner of the screen.

AddParameter

  • Set DismissButtonText in the Parameter Name field.

  • Select Text String from the Parameter Type dropdown menu.

  • Click the Save button.

  • Click the Confirm button to create the parameter.

Parameter6

TitleText

Add another parameter by clicking the Add Parameter button present at the top-right corner of the screen.

AddParameter

  • Set TitleText in the Parameter Name field.

  • Select Text String from the Parameter Type dropdown menu.

  • Toggle Required Field.

  • Click the Save button.

  • Click the Confirm button to create the parameter.

Parameter7

AttributionText

Add another parameter by clicking the Add Parameter button present at the top-right corner of the screen.

AddParameter

  • Set AttributionText in the Parameter Name field.

  • Select Text String from the Parameter Type dropdown menu.

  • Click the Save button.

  • Click the Confirm button to create the parameter.

Parameter8

BodyText1

Add another parameter by clicking the Add Parameter button present at the top-right corner of the screen.

AddParameter

  • Set BodyText1 in the Parameter Name field.

  • Select Text String from the Parameter Type dropdown menu.

  • Toggle Required Field.

  • Click the Save button.

  • Click the Confirm button to create the parameter.

Parameter9

BodyText2

Add another parameter by clicking the Add Parameter button present at the top-right corner of the screen.

AddParameter

  • Set BodyText2 in the Parameter Name field.

  • Select Text String from the Parameter Type dropdown menu.

  • Click the Save button.

  • Click the Confirm button to create the parameter.

Parameter10

LogoImage

Add another parameter by clicking the Add Parameter button present at the top-right corner of the screen.

AddParameter

  • Set LogoImage in the Parameter Name field.

  • Select Text String from the Parameter Type dropdown menu.

  • Click the Save button.

  • Click the Confirm button to create the parameter.

Parameter11

HeroImage

Add another parameter by clicking the Add Parameter button present at the top-right corner of the screen.

AddParameter

  • Set HeroImage in the Parameter Name field.

  • Select Text String from the Parameter Type dropdown menu.

  • Click the Save button.

  • Click the Confirm button to create the parameter.

Parameter12

Deadline

Add another parameter by clicking the Add Parameter button present at the top-right corner of the screen.

AddParameter

  • Set Deadline in the Parameter Name field.

  • Select Text String from the Parameter Type dropdown menu.

  • Click the Save button.

  • Click the Confirm button to create the parameter.

Parameter13

MaxUptimeDays

Add another parameter by clicking the Add Parameter button present at the top-right corner of the screen.

AddParameter

  • Set MaxUptimeDays in the Parameter Name field.

  • Select Number Value from the Parameter Type dropdown menu.

  • Click the Save button.

  • Click the Confirm button to create the parameter.

Parameter14

ADPasswordExpirationDays

Add another parameter by clicking the Add Parameter button present at the top-right corner of the screen.

AddParameter

  • Set ADPasswordExpirationDays in the Parameter Name field.

  • Select Number Value from the Parameter Type dropdown menu.

  • Click the Save button.

  • Click the Confirm button to create the parameter.

Parameter15

Repeat

Add another parameter by clicking the Add Parameter button present at the top-right corner of the screen.

AddParameter

  • Set Repeat in the Parameter Name field.

  • Select Text String from the Parameter Type dropdown menu.

  • Set Default Value to Once.

  • Click the Save button.

  • Click the Confirm button to create the parameter.

Parameter16

NotificationAppName

Add another parameter by clicking the Add Parameter button present at the top-right corner of the screen.

AddParameter

  • Set NotificationAppName in the Parameter Name field.

  • Select Text String from the Parameter Type dropdown menu.

  • Click the Save button.

  • Click the Confirm button to create the parameter.

Parameter17

MaxOccurrences

Add another parameter by clicking the Add Parameter button present at the top-right corner of the screen.

AddParameter

  • Set MaxOccurrences in the Parameter Name field.

  • Select Number Value from the Parameter Type dropdown menu.

  • Click the Save button.

  • Click the Confirm button to create the parameter.

Parameter18

RunScriptButton

Add another parameter by clicking the Add Parameter button present at the top-right corner of the screen.

AddParameter

  • Set RunScriptButton in the Parameter Name field.

  • Select Flag from the Parameter Type dropdown menu.

  • Set Default Value as False.

  • Click the Save button.

  • Click the Confirm button to create the parameter.

Parameter19

RunScriptButtonText

Add another parameter by clicking the Add Parameter button present at the top-right corner of the screen.

AddParameter

  • Set RunScriptButtonText in the Parameter Name field.

  • Select Text String from the Parameter Type dropdown menu.

  • Click the Save button.

  • Click the Confirm button to create the parameter.

Parameter20

ScriptPath

Add another parameter by clicking the Add Parameter button present at the top-right corner of the screen.

AddParameter

  • Set ScriptPath in the Parameter Name field.

  • Select Text String from the Parameter Type dropdown menu.

  • Click the Save button.

  • Click the Confirm button to create the parameter.

Parameter21

ScriptContext

Add another parameter by clicking the Add Parameter button present at the top-right corner of the screen.

AddParameter

  • Set ScriptContext in the Parameter Name field.

  • Select Text String from the Parameter Type dropdown menu.

  • Click the Save button.

  • Click the Confirm button to create the parameter.

Parameter22

ScriptStyle

Add another parameter by clicking the Add Parameter button present at the top-right corner of the screen.

AddParameter

  • Set ScriptStyle in the Parameter Name field.

  • Select Text String from the Parameter Type dropdown menu.

  • Click the Save button.

  • Click the Confirm button to create the parameter.

Parameter23

HideDismissButton

Add another parameter by clicking the Add Parameter button present at the top-right corner of the screen.

AddParameter

  • Set HideDismissButton in the Parameter Name field.

  • Select Flag from the Parameter Type dropdown menu.

  • Set Default Value as False.

  • Click the Save button.

  • Click the Confirm button to create the parameter.

Parameter24

Parameters block

ParameterBlock

Task

Navigate to the Script Editor Section and start by adding a row. You can do this by clicking the Add Row button at the bottom of the script page.

NewTask

A blank function will appear.

BlankFunction

Row 1 Function: PowerShell Script

Search and select the PowerShell Script function.

F1Image1

The following function will pop up on the screen:

F1Image2

Paste in the following PowerShell script and set the expected time of script execution to 900 seconds. Click the Save button.

if ( '@NotificationType@' -notin ('Generic', 'PendingRebootUptime', 'PendingRebootCheck', 'ADPasswordExpiration') ) {
return "NotificationType can either be 'Generic', 'PendingRebootUptime', 'PendingRebootCheck', 'ADPasswordExpiration'."
} else {
$NotificationType = '@NotificationType@'
}

if (('@RebootButton@' -match '1|Yes|True|Y') -and ($NotificationType -in ('Generic', 'PendingRebootUptime', 'PendingRebootCheck'))) {
$RebootButton = $true
} else {
$RebootButton = $false
}

if ('@RunScriptButton@' -match '1|Yes|True|Y') {
$RunScriptButton = $true
} else {
$RunScriptButton = $false
}

if (('@RunScriptButtonText@').length -ge 1 -and '@RunScriptButtonText@' -notmatch 'RunScriptButtonText' -and $RunScriptButton) {
$RunScriptButtonText = '@RunScriptButtonText@'
} else {
$RunScriptButtonText = ''
}

if (('@ScriptPath@').Length -ge 3 -and '@ScriptPath@' -notmatch 'ScriptPath' -and $RunScriptButton) {
$ScriptPath = '@ScriptPath@'
} else {
$ScriptPath = ''
}

if (!$ScriptPath -and $RunScriptButton) {
return 'ScriptPath is not provided and RunScriptButton is enabled.'
}

if (('@ScriptContext@').Length -ge 3 -and '@ScriptContext@' -notmatch 'ScriptContext' -and $RunScriptButton) {
$ScriptContext = '@ScriptContext@'
} else {
$ScriptContext = ''
}

if (('@ScriptStyle@').Length -ge 3 -and '@ScriptStyle@' -notmatch 'ScriptStyle' -and $RunScriptButton) {
$ScriptStyle = '@ScriptStyle@'
} else {
$ScriptStyle = ''
}

if ('@LearnMoreButton@' -match '1|Yes|True|Y') {
$LearnMoreButton = $true
} else {
$LearnMoreButton = $false
}

if (('@LearnMoreUrl@' -match ('[hf]t{1,2}ps{0,1}')) -and ($LearnMoreButton -eq $true)) {
$LearnMoreUrl = '@LearnMoreUrl@'
} else {
$LearnMoreUrl = ''
}

if (('@SnoozeButton@' -match '1|Yes|True|Y') -and ($LearnMoreButton -eq $False) -and ($RunScriptButton -eq $false)) {
$SnoozeButton = $true
} else {
$SnoozeButton = $false
}

if ('@HideDismissButton@' -match '1|Yes|True|Y') {
$HideDismissButton = $true
} else {
$HideDismissButton = $false
}

if ((('@DismissButtonText@').length -le 2) -or ('@DismissButtonText@' -match 'DismissButtonText') -or ($HideDismissButton -eq $true)) {
$DismissButtonText = ''
} else {
$DismissButtonText = '@DismissButtonText@'
}

if ((('@TitleText@').length -le 2 ) -or ('@TitleText@' -match 'TitleText')) {
return 'TitleText is mandatory to Set the title of the notification'
} else {
$TitleText = '@TitleText@'
}

if ((('@AttributionText@').length -le 2) -or ('@AttributionText@' -match 'AttributionText')) {
$AttributionText = '%companyname%'
} else {
$AttributionText = '@AttributionText@'
}

if ((('@BodyText1@').length -le 2 ) -or ('@BodyText1@' -match 'BodyText1')){
return 'BodyText1 is mandatory to Set the main text content of the notification body'
} else {
$BodyText1 = '@BodyText1@'
}

if ((('@BodyText2@').length -le 2) -or ('@BodyText2@' -match 'BodyText2')) {
$BodyText2 = ''
} else {
$BodyText2 = '@BodyText2@'
}

if (('@LogoImage@').length -gt 2) {
$LogoImage = '@LogoImage@'
} else {
$LogoImage = ''
}

if ( ('@HeroImage@').length -gt 2) {
$HeroImage = '@HeroImage@'
} else {
$HeroImage = ''
}

if ('@Deadline@' -match '\d{4}-\d{2}-\d{2}' -and $RunScriptButton -eq $false) {
$Deadline = [datetime]'@Deadline@'
} else {
$Deadline = ''
}

if (('@MaxUptimeDays@' -match '[0-9]{1,}') -and (('@MaxUptimeDays@').length -ge 1) -and ($NotificationType -match 'PendingRebootUptime')) {
$MaxUptimeDays = '@MaxUptimeDays@'
} else {
$MaxUptimeDays = ''
}

if (('@ADPasswordExpirationDays@' -match '[0-9]{1,}') -and (('@ADPasswordExpirationDays@').length -ge 1) -and ($NotificationType -match 'ADPasswordExpiration')) {
$ADPasswordExpirationDays = '@ADPasswordExpirationDays@'
} else {
$ADPasswordExpirationDays = ''
}

if (('@Repeat@' -match '(Once|Hourly|[0-9]{1,}Minutes|[0-9]{1,}Hours|Daily|[0-9]{1,}Days|Weekly|Monthly|AtLogon)') -and (('@Repeat@').length -gt 2)) {
$Repeat = '@Repeat@'
} else {
$Repeat = 'Once'
}

if ('@NotificationAppName@' -match '[0-9A-z]{1,}' -and (('@NotificationAppName@').length -gt 2) -and ('@NotificationAppName@' -notmatch 'NotificationAppName')) {
$NotificationAppName = '@NotificationAppName@'
} else {
$NotificationAppName = ''
}

if ('@MaxOccurrences@' -match '[0-9]{1,}' -and (('@MaxOccurrences@').length -ge 1) -and ('@MaxOccurrences@' -notmatch 'MaxOccurrences')) {
$MaxOccurrences = '@MaxOccurrences@'
} else {
$MaxOccurrences = ''
}

$parameters = @{
TitleText = $TitleText
BodyText1 = $BodyText1
Repeat = $Repeat
}

switch ($NotificationType) {
'Generic' {
$parameters.Add('Generic', $true)
}
'PendingRebootUptime' {
$parameters.Add('PendingRebootUptime', $true)
}
'PendingRebootCheck' {
$parameters.Add('PendingRebootCheck', $true)
}
'ADPasswordExpiration' {
$parameters.Add('ADPasswordExpiration', $true)
}
default {
$parameters.Add('Generic', $true)
}
}

if ($RebootButton -eq $true) { $parameters.Add('RebootButton', $RebootButton) }
if ($RunScriptButton -eq $true) { $parameters.Add('RunScriptButton', $RunScriptButton) }
if ($RunScriptButtonText -ne '') { $parameters.Add('RunScriptButtonText', $RunScriptButtonText) }
if ($ScriptPath -ne '') { $parameters.Add('ScriptPath', $ScriptPath) }
if ($ScriptContext -ne '') { $parameters.Add('ScriptContext', $ScriptContext) }
if ($ScriptStyle -ne '') { $parameters.Add('ScriptStyle', $ScriptStyle) }
if ($LearnMoreButton -eq $true) { $parameters.Add('LearnMoreButton', $LearnMoreButton) }
if ($LearnMoreUrl -ne '') { $parameters.Add('LearnMoreUrl', $LearnMoreUrl) }
if ($SnoozeButton -eq $true) { $parameters.Add('SnoozeButton', $SnoozeButton) }
if ($HideDismissButton -ne '') { $parameters.Add('HideDismissButton', $HideDismissButton) }
if ($DismissButtonText -ne '') { $parameters.Add('DismissButtonText', $DismissButtonText) }
if ($AttributionText -ne '') { $parameters.Add('AttributionText', $AttributionText) }
if ($BodyText2 -ne '') { $parameters.Add('BodyText2', $BodyText2) }
if ($LogoImage -ne '') { $parameters.Add('LogoImage', $LogoImage) }
if ($HeroImage -ne '') { $parameters.Add('HeroImage', $HeroImage) }
if ($Deadline -ne '') { $parameters.Add('Deadline', $Deadline) }
if ($MaxUptimeDays -ne '') { $parameters.Add('MaxUptimeDays', $MaxUptimeDays) }
if ($ADPasswordExpirationDays -ne '') { $parameters.Add('ADPasswordExpirationDays', $ADPasswordExpirationDays) }
if ($NotificationAppName -ne '') { $parameters.Add('NotificationAppName', $NotificationAppName) }
if ($MaxOccurrences -ne '') { $parameters.Add('MaxOccurrences', $MaxOccurrences) }

#region Setup - Variables
$ProjectName = 'Invoke-ToastNotification'
[Net.ServicePointManager]::SecurityProtocol = [enum]::ToObject([Net.SecurityProtocolType], 3072)
$BaseURL = 'https://file.provaltech.com/repo'
$PS1URL = "$BaseURL/script/$ProjectName.ps1"
$WorkingDirectory = "C:\ProgramData\_automation\script\$ProjectName"
$PS1Path = "$WorkingDirectory\$ProjectName.ps1"
$LogPath = "$WorkingDirectory\$ProjectName-log.txt"
$ErrorLogPath = "$WorkingDirectory\$ProjectName-Error.txt"
#endregion

#region Setup - Folder Structure
New-Item -Path $WorkingDirectory -ItemType Directory -ErrorAction SilentlyContinue | Out-Null

if (-not ( ( ( Get-Acl $WorkingDirectory ).Access | Where-Object { $_.IdentityReference -match 'EveryOne' } ).FileSystemRights -match 'FullControl' ) ) {
$Acl = Get-Acl $WorkingDirectory
$AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule('Everyone', 'FullControl', 'ContainerInherit, ObjectInherit', 'none', 'Allow')
$Acl.AddAccessRule($AccessRule)
Set-Acl $WorkingDirectory $Acl
}

$response = Invoke-WebRequest -Uri $PS1URL -UseBasicParsing

if (($response.StatusCode -ne 200) -and (!(Test-Path -Path $PS1Path))) {
return "No pre-downloaded script exists and the script '$PS1URL' failed to download. Exiting."
} elseif ($response.StatusCode -eq 200) {
Remove-Item -Path $PS1Path -ErrorAction SilentlyContinue
[System.IO.File]::WriteAllLines($PS1Path, $response.Content)
}

if (!(Test-Path -Path $PS1Path)) {
return 'An error occurred and the script was unable to be downloaded. Exiting.'
}
#endregionSetup

#region Execution
Write-Information "Executing $PS1Path with parameters: $($parameters | Out-String)" -InformationAction Continue
if ($parameters) {
& $PS1Path @parameters
} else {
& $PS1Path
}
#endregion

if ( !(Test-Path $LogPath) ) {
return 'PowerShell Failure. A Security application seems to have restricted the execution of the PowerShell Script.'
}

$logContent = Get-Content -Path $LogPath
$logContent[ $($($logContent.IndexOf($($logContent -match "$($ProjectName)$")[-1])) + 1)..$($logContent.length - 1) ]

if ( Test-Path $ErrorLogPath ) {
$ErrorContent = ( Get-Content -Path $ErrorLogPath )
return ($ErrorContent | Out-String)
}

F1Image3

Flag the Continue on Failure button.

F1Image4

Row 2 Function: Script Log

Insert a new row by clicking the Add Row button.

AddRow

Select the Script Log function.

F2Image1

F2Image2

In the script log message, simply type %output% so that the script will send the results of the PowerShell script above to the output on the Automation tab for the target device.

F2Image3

Completed Task

CompletedTask

Output

  • Script Logs