Home > Back-end >  Popup Yes/No message Box When Launching Powershell From a Batch File
Popup Yes/No message Box When Launching Powershell From a Batch File

Time:05-26

I'm struggling to find an answer to this, which might mean I'm asking the wrong questions.

I wrote a PS1 script that had popups and everything worked great! I used this method:

$msgBoxInput =  [System.Windows.MessageBox]::Show("You are about to publish Part $UserPart1, would you like to coninue?",'Confirm Update','YesNo')switch  ($msgBoxInput) 
      {
          'Yes' 
          {
          Runs Code
          }
          'No' 
          {
          Return
          }
      }

That worked perfectly. That is until I launched the PS1 using a batch file.

This is the code I'm using to run the batch file:

Powershell.exe -executionpolicy remotesigned -windowstyle hidden -File  "C:\Updater 2.0.ps1"

The batch file works, but the popups don't happen.

So I switched gears and tried using the popups like this:

 $msgBoxInput =  [System.Windows.MessageBox]::Show("You are about to publish Part $UserPart1, would you like to coninue?",'Confirm Update','YesNo')

      

Once again, the message box doesn't pop up. If I remove the "$msgBoxInput =" at the start of the message, the box pops up, but it doesn't matter what the users selects, the code just runs as if they pressed "Yes."

This may be the totally wrong approach, I honestly don't know. I've always used batch files for my user group (I've got 30 users) because it's easier than trying to use the actual PS1. If there is a better/easier route, I'm all ears!

This is my first form using PS1 so I could be doing something just super wrong too.

Thank you all for your help.

CodePudding user response:

enter image description here

Powershell.exe -executionpolicy remotesigned -File D:\PShell\SO\72366658.ps1
Runs Code
  • Related