Want to Show a vbScript MsgBox in Powershell ?

I wanted to ask before I closed my Excel spreadsheet. In vbScript, I used a msgbox for this.
I found this process for PowerShell and it works.
 
#<—– Start POSH Script ————————————————————->
 
Function Show-Msgbox {
  Param([string]$message=$(Throw "You must specify a message"),
      [string]$button="okonly",
      [string]$icon="Question",
      [string]$title="Message Box"
     )
    
# Buttons: OkOnly, OkCancel, AbortRetryIgnore, YesNoCancel, YesNo, RetryCancel
# Icons: Critical, Question, Exclamation, Information
  [reflection.assembly]::loadwithpartialname("microsoft.visualbasic") | Out-Null
  [microsoft.visualbasic.interaction]::Msgbox($message,"$button,$icon",$title)
 }
 
$rc=Show-Msgbox -message "Do you want to view the Spredsheet?" `
-icon "exclamation" -button "YesNoCancel" -title "Hey $env:username!!"
Switch ($rc) {
 "Yes" {$xl.Visible = $True }
 # close and release resources
 "No" {$y.close($false)
  $xl.quit()
  spps -n excel } #<—- This will shut down every instance of Excell (for sure!)
 "cancel" {"When in doubt, punt."}
}
#<———— End of Script ————————————————————->
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s