Thursday, 23 January 2014

Show-Message.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script creates a function to display a message 
  4.     in a message block, then demonstrates its usage 
  5. .DESCRIPTION 
  6.     This script used Windows Forms to put up a message 
  7.     box containing text and a window title passed as  
  8.     parameters 
  9. .NOTES 
  10.     File Name  : Show-Message.ps1 
  11.     Author     : Thomas Lee - tfl@psp.co.uk 
  12.     Requires   : PowerShell Version 3.0 
  13. .LINK 
  14.     This script posted to: 
  15.         http://www.pshscripts.blogspot.com 
  16. .EXAMPLE 
  17.     Left as an exercise to the Reader 
  18. #> 
  19.  
  20. Function Show-Message { 
  21.  
  22. [CmdletBinding()] 
  23. Param (  
  24.    [Parameter(Mandatory=$True,  
  25.               HelpMessage="Content of Message box")] 
  26.    [string]$Message
  27.  
  28.    [Parameter(Mandatory=$False
  29.              HelpMessage="Title for Message box")] 
  30.    [string]$BoxTitle = "Message" 
  31. )           
  32.  
  33. # Just in case, load the relevant assembly 
  34. $v1 = [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms"
  35.  
  36. # Now use the messagebox class to display the message 
  37. [Windows.Forms.MessageBox]::Show($Message, $BoxTitle,  
  38.        [Windows.Forms.MessageBoxButtons]::OK ,  
  39.        [Windows.Forms.MessageBoxIcon]::Information)  
  40.  
  41. } # End of function 
  42.  
  43. # Set an alias 
  44. Set-Alias sm Show-Message 
  45.  
  46. # call the function 
  47. sm 'testing' 'details, details' 
Technorati Tags: ,

1 comment:

Doe John said...

This is pretty sweet. Thanks man!