PoshCode Archive  Artifact [cf4e83d4d8]

Artifact cf4e83d4d89212b77b298033484870ab68f2fb7ffbf099990f12d4a20998fcf5:

  • File VB-MsgBox-Powershell.ps1 — part of check-in [0fc7ebb4ad] at 2018-06-10 13:25:20 on branch trunk — This is an advanced function I found that I’ve been using as a Show-Msgbox Function. Enjoy :) (user: Dyspareunia size: 4264)

# encoding: ascii
# api: powershell
# title: VB MsgBox Powershell
# description: This is an advanced function I found that I’ve been using as a Show-Msgbox Function. Enjoy :)
# version: 0.1
# type: script
# author: Dyspareunia
# license: CC0
# function: Show-MsgBox
# x-poshcode-id: 3419
# x-archived: 2014-03-19T08:49:22
# x-published: 2014-05-20T16:18:00
#
#
<# 
            .SYNOPSIS  
            Shows a graphical message box, with various prompt types available. 
 
            .DESCRIPTION 
            Emulates the Visual Basic MsgBox function.  It takes four parameters, of which only the prompt is mandatory 
 
            .INPUTS 
            The parameters are:- 
             
            Prompt (mandatory):  
                Text string that you wish to display 
                 
            Title (optional): 
                The title that appears on the message box 
                 
            Icon (optional).  Available options are: 
                Information, Question, Critical, Exclamation (not case sensitive) 
                
            BoxType (optional). Available options are: 
                OKOnly, OkCancel, AbortRetryIgnore, YesNoCancel, YesNo, RetryCancel (not case sensitive) 
                 
            DefaultButton (optional). Available options are: 
                1, 2, 3 
 
            .OUTPUTS 
            Microsoft.VisualBasic.MsgBoxResult 
 
            .EXAMPLE 
            C:\PS> Show-MsgBox Hello 
            Shows a popup message with the text "Hello", and the default box, icon and defaultbutton settings. 
 
            .EXAMPLE 
            C:\PS> Show-MsgBox -Prompt "This is the prompt" -Title "This Is The Title" -Icon Critical -BoxType YesNo -DefaultButton 2 
            Shows a popup with the parameter as supplied. 
 
            .LINK 
            http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.msgboxresult.aspx 
 
            .LINK 
            http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.msgboxstyle.aspx 
            #> 
# By BigTeddy August 24, 2011 
# http://social.technet.microsoft.com/profile/bigteddy/. 
 
function Show-MsgBox 
{ 
 
 [CmdletBinding()] 
    param( 
    [Parameter(Position=0, Mandatory=$true)] [string]$Prompt, 
    [Parameter(Position=1, Mandatory=$false)] [string]$Title ="", 
    [Parameter(Position=2, Mandatory=$false)] [ValidateSet("Information", "Question", "Critical", "Exclamation")] [string]$Icon ="Information", 
    [Parameter(Position=3, Mandatory=$false)] [ValidateSet("OKOnly", "OKCancel", "AbortRetryIgnore", "YesNoCancel", "YesNo", "RetryCancel")] [string]$BoxType ="OkOnly", 
    [Parameter(Position=4, Mandatory=$false)] [ValidateSet(1,2,3)] [int]$DefaultButton = 1 
    ) 
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.VisualBasic") | Out-Null 
switch ($Icon) { 
            "Question" {$vb_icon = [microsoft.visualbasic.msgboxstyle]::Question } 
            "Critical" {$vb_icon = [microsoft.visualbasic.msgboxstyle]::Critical} 
            "Exclamation" {$vb_icon = [microsoft.visualbasic.msgboxstyle]::Exclamation} 
            "Information" {$vb_icon = [microsoft.visualbasic.msgboxstyle]::Information}} 
switch ($BoxType) { 
            "OKOnly" {$vb_box = [microsoft.visualbasic.msgboxstyle]::OKOnly} 
            "OKCancel" {$vb_box = [microsoft.visualbasic.msgboxstyle]::OkCancel} 
            "AbortRetryIgnore" {$vb_box = [microsoft.visualbasic.msgboxstyle]::AbortRetryIgnore} 
            "YesNoCancel" {$vb_box = [microsoft.visualbasic.msgboxstyle]::YesNoCancel} 
            "YesNo" {$vb_box = [microsoft.visualbasic.msgboxstyle]::YesNo} 
            "RetryCancel" {$vb_box = [microsoft.visualbasic.msgboxstyle]::RetryCancel}} 
switch ($Defaultbutton) { 
            1 {$vb_defaultbutton = [microsoft.visualbasic.msgboxstyle]::DefaultButton1} 
            2 {$vb_defaultbutton = [microsoft.visualbasic.msgboxstyle]::DefaultButton2} 
            3 {$vb_defaultbutton = [microsoft.visualbasic.msgboxstyle]::DefaultButton3}} 
$popuptype = $vb_icon -bor $vb_box -bor $vb_defaultbutton 
$ans = [Microsoft.VisualBasic.Interaction]::MsgBox($prompt,$popuptype,$title) 
return $ans 
} #end function