Advertisement
easternnl

Show-Popup

Dec 3rd, 2015
572
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [CmdletBinding()][OutputType([int])]Param(
  2.     [parameter(Mandatory=$true, ValueFromPipeLine=$true)][Alias("Msg")][string]$Message,
  3.     [parameter(Mandatory=$false, ValueFromPipeLine=$false)][Alias("Ttl")][string]$Title = $null,
  4.     [parameter(Mandatory=$false, ValueFromPipeLine=$false)][Alias("Duration")][int]$TimeOut = 0,
  5.     [parameter(Mandatory=$false, ValueFromPipeLine=$false)][Alias("But","BS")][ValidateSet( "OK", "OC", "AIR", "YNC" , "YN" , "RC")][string]$ButtonSet = "OK",
  6.     [parameter(Mandatory=$false, ValueFromPipeLine=$false)][Alias("ICO")][ValidateSet( "None", "Critical", "Question", "Exclamation" , "Information" )][string]$IconType = "None"
  7.      )
  8.  
  9. Function Show-PopUp{
  10.     [CmdletBinding()][OutputType([int])]Param(
  11.         [parameter(Mandatory=$true, ValueFromPipeLine=$true)][Alias("Msg")][string]$Message,
  12.         [parameter(Mandatory=$false, ValueFromPipeLine=$false)][Alias("Ttl")][string]$Title = $null,
  13.         [parameter(Mandatory=$false, ValueFromPipeLine=$false)][Alias("Duration")][int]$TimeOut = 0,
  14.         [parameter(Mandatory=$false, ValueFromPipeLine=$false)][Alias("But","BS")][ValidateSet( "OK", "OC", "AIR", "YNC" , "YN" , "RC")][string]$ButtonSet = "OK",
  15.         [parameter(Mandatory=$false, ValueFromPipeLine=$false)][Alias("ICO")][ValidateSet( "None", "Critical", "Question", "Exclamation" , "Information" )][string]$IconType = "None"
  16.          )
  17.    
  18.     $ButtonSets = "OK", "OC", "AIR", "YNC" , "YN" , "RC"
  19.     $IconTypes  = "None", "Critical", "Question", "Exclamation" , "Information"
  20.     $IconVals = 0,16,32,48,64
  21.     if((Get-Host).Version.Major -ge 3){
  22.         $Button   = $ButtonSets.IndexOf($ButtonSet)
  23.         $Icon     = $IconVals[$IconTypes.IndexOf($IconType)]
  24.         }
  25.     else{
  26.         $ButtonSets|ForEach-Object -Begin{$Button = 0;$idx=0} -Process{ if($_.Equals($ButtonSet)){$Button = $idx           };$idx++ }
  27.         $IconTypes |ForEach-Object -Begin{$Icon   = 0;$idx=0} -Process{ if($_.Equals($IconType) ){$Icon   = $IconVals[$idx]};$idx++ }
  28.         }
  29.     $objShell = New-Object -com "Wscript.Shell"
  30.     $objShell.Popup($Message,$TimeOut,$Title,$Button+$Icon)
  31.  
  32.     <#
  33.         .SYNOPSIS
  34.             Creates a Timed Message Popup Dialog Box.
  35.  
  36.         .DESCRIPTION
  37.             Creates a Timed Message Popup Dialog Box.
  38.  
  39.         .OUTPUTS
  40.             The Value of the Button Selected or -1 if the Popup Times Out.
  41.            
  42.             Values:
  43.                 -1 Timeout  
  44.                  1  OK
  45.                  2  Cancel
  46.                  3  Abort
  47.                  4  Retry
  48.                  5  Ignore
  49.                  6  Yes
  50.                  7  No
  51.  
  52.         .PARAMETER Message
  53.             [string] The Message to display.
  54.  
  55.         .PARAMETER Title
  56.             [string] The MessageBox Title.
  57.  
  58.         .PARAMETER TimeOut
  59.             [int]   The Timeout Value of the MessageBox in seconds.
  60.                     When the Timeout is reached the MessageBox closes and returns a value of -1.
  61.                     The Default is 0 - No Timeout.
  62.  
  63.         .PARAMETER ButtonSet
  64.             [string] The Buttons to be Displayed in the MessageBox.
  65.  
  66.                      Values:
  67.                         Value     Buttons
  68.                         OK        OK                   - This is the Default          
  69.                         OC        OK Cancel          
  70.                         AIR       Abort Ignore Retry
  71.                         YNC       Yes No Cancel    
  72.                         YN        Yes No            
  73.                         RC        Retry Cancel      
  74.  
  75.         .PARAMETER IconType
  76.             [string] The Icon to be Displayed in the MessageBox.
  77.  
  78.                      Values:
  79.                         None      - This is the Default
  80.                         Critical    
  81.                         Question    
  82.                         Exclamation
  83.                         Information
  84.            
  85.         .EXAMPLE
  86.             $RetVal = Show-PopUp -Message "Data Trucking Company" -Title "Popup Test" -TimeOut 5 -ButtonSet YNC -Icon Exclamation
  87.  
  88.         .NOTES
  89.             FunctionName : Show-PopUp
  90.             Created by   : Data Trucking Company
  91.             Date Coded   : 06/25/2012 16:55:46
  92.  
  93.         .LINK
  94.            
  95.      #>
  96.  
  97. }
  98.  
  99.  
  100. Show-PopUp -Message $Message -Title $Title -TimeOut $TimeOut -ButtonSet $ButtonSet -IconType $IconType
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement