Message box with powershell studio - passing variables

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
Isaac99
Posts: 17
Joined: Fri Dec 13, 2019 4:37 am

Message box with powershell studio - passing variables

Post by Isaac99 »

Using some code from an earlier posting on here, Is there a way to display variables in a message box?
I have tried various versions of the below with and without parentheses, "", ' etc but it just displays the variable name and not the content?

if('Yes' -eq [System.Windows.Forms.MessageBox]::Show('Are you sure you want to kill process $($process) on computer $($computername)','Warning',[System.Windows.Forms.MessageBoxButtons]::YesNo)){
#Do Stuff
}

jvierra
Posts: 14452
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Message box with powershell studio - passing variables

Post by jvierra »

This is the correct way to do this:

Code: Select all

$msg = "Are you sure you want to kill process $process on computer $computername"
if('Yes' -eq [System.Windows.Forms.MessageBox]::Show($msg,'Warning','YesNo')){
#Do Stuff
}
Start by reading the following:

help about_quoting

Isaac99
Posts: 17
Joined: Fri Dec 13, 2019 4:37 am

Re: Message box with powershell studio - passing variables

Post by Isaac99 »

Awesome thanks very much

Locked