Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [CmdletBinding()][OutputType([int])]Param(
- [parameter(Mandatory=$true, ValueFromPipeLine=$true)][Alias("Msg")][string]$Message,
- [parameter(Mandatory=$false, ValueFromPipeLine=$false)][Alias("Ttl")][string]$Title = $null,
- [parameter(Mandatory=$false, ValueFromPipeLine=$false)][Alias("Duration")][int]$TimeOut = 0,
- [parameter(Mandatory=$false, ValueFromPipeLine=$false)][Alias("But","BS")][ValidateSet( "OK", "OC", "AIR", "YNC" , "YN" , "RC")][string]$ButtonSet = "OK",
- [parameter(Mandatory=$false, ValueFromPipeLine=$false)][Alias("ICO")][ValidateSet( "None", "Critical", "Question", "Exclamation" , "Information" )][string]$IconType = "None"
- )
- Function Show-PopUp{
- [CmdletBinding()][OutputType([int])]Param(
- [parameter(Mandatory=$true, ValueFromPipeLine=$true)][Alias("Msg")][string]$Message,
- [parameter(Mandatory=$false, ValueFromPipeLine=$false)][Alias("Ttl")][string]$Title = $null,
- [parameter(Mandatory=$false, ValueFromPipeLine=$false)][Alias("Duration")][int]$TimeOut = 0,
- [parameter(Mandatory=$false, ValueFromPipeLine=$false)][Alias("But","BS")][ValidateSet( "OK", "OC", "AIR", "YNC" , "YN" , "RC")][string]$ButtonSet = "OK",
- [parameter(Mandatory=$false, ValueFromPipeLine=$false)][Alias("ICO")][ValidateSet( "None", "Critical", "Question", "Exclamation" , "Information" )][string]$IconType = "None"
- )
- $ButtonSets = "OK", "OC", "AIR", "YNC" , "YN" , "RC"
- $IconTypes = "None", "Critical", "Question", "Exclamation" , "Information"
- $IconVals = 0,16,32,48,64
- if((Get-Host).Version.Major -ge 3){
- $Button = $ButtonSets.IndexOf($ButtonSet)
- $Icon = $IconVals[$IconTypes.IndexOf($IconType)]
- }
- else{
- $ButtonSets|ForEach-Object -Begin{$Button = 0;$idx=0} -Process{ if($_.Equals($ButtonSet)){$Button = $idx };$idx++ }
- $IconTypes |ForEach-Object -Begin{$Icon = 0;$idx=0} -Process{ if($_.Equals($IconType) ){$Icon = $IconVals[$idx]};$idx++ }
- }
- $objShell = New-Object -com "Wscript.Shell"
- $objShell.Popup($Message,$TimeOut,$Title,$Button+$Icon)
- <#
- .SYNOPSIS
- Creates a Timed Message Popup Dialog Box.
- .DESCRIPTION
- Creates a Timed Message Popup Dialog Box.
- .OUTPUTS
- The Value of the Button Selected or -1 if the Popup Times Out.
- Values:
- -1 Timeout
- 1 OK
- 2 Cancel
- 3 Abort
- 4 Retry
- 5 Ignore
- 6 Yes
- 7 No
- .PARAMETER Message
- [string] The Message to display.
- .PARAMETER Title
- [string] The MessageBox Title.
- .PARAMETER TimeOut
- [int] The Timeout Value of the MessageBox in seconds.
- When the Timeout is reached the MessageBox closes and returns a value of -1.
- The Default is 0 - No Timeout.
- .PARAMETER ButtonSet
- [string] The Buttons to be Displayed in the MessageBox.
- Values:
- Value Buttons
- OK OK - This is the Default
- OC OK Cancel
- AIR Abort Ignore Retry
- YNC Yes No Cancel
- YN Yes No
- RC Retry Cancel
- .PARAMETER IconType
- [string] The Icon to be Displayed in the MessageBox.
- Values:
- None - This is the Default
- Critical
- Question
- Exclamation
- Information
- .EXAMPLE
- $RetVal = Show-PopUp -Message "Data Trucking Company" -Title "Popup Test" -TimeOut 5 -ButtonSet YNC -Icon Exclamation
- .NOTES
- FunctionName : Show-PopUp
- Created by : Data Trucking Company
- Date Coded : 06/25/2012 16:55:46
- .LINK
- #>
- }
- Show-PopUp -Message $Message -Title $Title -TimeOut $TimeOut -ButtonSet $ButtonSet -IconType $IconType
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement