Public/New-WFInputBox.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
function New-WFInputBox { <# .SYNOPSIS The New-WFInputBox function will prompt the user for input in a window. .DESCRIPTION The New-WFInputBox function will prompt the user for input in a window. .PARAMETER Message Specifies the question you want to ask to the user. .PARAMETER Title Specifies the title of the window. .PARAMETER DefaultInputText Specifies the default answer text. .EXAMPLE PS C:\> New-WFInputBox -Message 'What is your computer name' -Title 'Computer' -DefaultInputText "$env:ComputerName" .NOTES Author: Francois-Xavier Cat Twitter:@LazyWinAdm www.lazywinadmin.com github.com/lazywinadmin #> [CmdletBinding(SupportsShouldProcess = $true)] param ( [Parameter(Mandatory = $true)] [string]$Message, [Alias('WindowsTitle')] [string]$Title, [Alias('DefaultText')] [string]$DefaultInputText ) BEGIN { TRY { # Load the Assembly Add-Type -AssemblyName Microsoft.VisualBasic -ErrorAction 'Stop' -ErrorVariable ErrorBeginAddType } CATCH { Write-Warning -message "[BEGIN] Something wrong happened" IF ($ErrorBeginAddType) { Write-Warning -message "[BEGIN] Error while loading assembly Microsoft.VisualBasic" } Write-Error -message $Error[0].Exception.Message } } PROCESS { if ($PSCmdlet.ShouldProcess("InputBox", "Show a new Input box with the following message: $Message")) { #[Microsoft.VisualBasic.Interaction]::InputBox($Message, $Title, $DefaultInputText, $XPosition, $YPosition) Write-output $([Microsoft.VisualBasic.Interaction]::InputBox($Message, $Title, $DefaultInputText)) } } } #New-InputBox |