BurntToast icon indicating copy to clipboard operation
BurntToast copied to clipboard

Allow variable names to be displayed in the toast notification

Open Hexuzerfire opened this issue 2 years ago • 1 comments

Planning to use this for when a specific account logs into a specific computer. Using Task scheduler to fire off the following .ps1 script:

$PCName=(Get-CimInstance -ClassName Win32_ComputerSystem).Name $CurrentDate=Get-Date Invoke-Command -ComputerName <Remote Computer> -ScriptBlock {New-BurntToastNotification -Text "SPECIFIED ACCOUNT HAS LOGGED IN TO $PCName ON $CurrentDate" -Sound 'Alarm2'}

Currently the variables are missing when the toast notification comes up.

Thanks :)

Hexuzerfire avatar Jun 06 '23 14:06 Hexuzerfire

What you're running into there is a scoping issue. When running Invoke-Command the ScriptBlock runs in an environment where those variables do not exist.

The "using" scope should fix this, e.g. "SPECIFIED ACCOUNT HAS LOGGED IN TO $using:PCName ON $using:CurrentDate"

Check out this post for more info: https://powershellexplained.com/2016-08-28-PowerShell-variables-to-remote-commands/

Windos avatar Oct 11 '23 06:10 Windos