Setting a variable with a msgbox (or radio button)

rated by 0 users
Not Answered This post has 0 verified answers | 2 Replies | 2 Followers

Not Ranked
4 Posts
schatham posted on 04-24-2012 1:52 PM

I am working on a Powershell script to eliminate some of the manual configuration that's currently necessary to run it.  One of the pieces of it is where I set a variable to send a deleted item to the Recycle bin or to delete it permanently.

Currently, that is a variable that I have set to either "Kill" or "Recycle" inside the script.  


What I want to do is to prompt the user with the choices, but all I've found thus far is a repurposing of the msgbox that has YesNo, Yes/NoCancel, etc selections.  Ideally, I'd like a message box to be presented with buttons that gives the user a choice between one or the other & set the variable based on what they clicked.  

The prompt in the messagebox would say "Choose to Recycle (default) or to permanently delete files (cannot be recovered)".  with buttons on the bottom saying Kill or Recycle, with Recycle selected.  If they click the X on the box, it should default to Recycle.  

The ideal solution would be if I had 3 choices (or more) and could present a messagebox with the options presented that would then store the response for later use. 

This may be more suited to using another type of prompt, so I'm open to any alternatives.  Any ideas thoughts appreciated.

All Replies

Top 10 Contributor
640 Posts

You can do this with a dialog, but it's pure Windows Forms (.NET) programming. Bit out of scope for a PowerShell Q&A. You'd essentially need to construct a custom form - the built-in easy message box stuff only supports the canned buttons, not custom ones.

You CAN do a custom prompt that's more PowerShell-native - like the one that you get when you run Set-ExecutionPolicy. has a pretty good description, although it's for a yes/no prompt - you could obviously customize it. is also a very clear implementation of the same technique. 

Not Ranked
4 Posts

I can make this suit my needs.  Many thanks for pointing me in the right direction!


Page 1 of 1 (3 items) | RSS
Copyright 2012 All rights reserved.