Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow variable names to be displayed in the toast notification #220

Open
Hexuzerfire opened this issue Jun 6, 2023 · 1 comment
Open
Assignees

Comments

@Hexuzerfire
Copy link

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 -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 :)

@Windos
Copy link
Owner

Windos commented Oct 11, 2023

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants