PoshCode Archive  Artifact Content

Artifact ea09510068fe2b24efae0442a636932d362ae7273a4a93a3ed37b56aa0f969ff:

  • File ScriptMethod-Example.ps1 — part of check-in [74e86b403a] at 2018-06-10 13:29:58 on branch trunk — An example of a script method with mandatory parameters (user: Joel Bennett size: 730)

# encoding: ascii
# api: powershell
# title: ScriptMethod Example
# description: An example of a script method with mandatory parameters
# version: 0.1
# type: script
# author: Joel Bennett
# license: CC0
# x-poshcode-id: 3719
# x-archived: 2016-05-26T08:22:08
# x-published: 2013-10-29T18:52:00
#
#
$x = New-Object PSObject | Add-Member -MemberType ScriptMethod -Name Test -Value {
    .{
        param (	
            [Parameter(Mandatory=$true)]
            [ValidateNotNullOrEmpty()]
	        [string]$Message
        )
        "This is the message: $Message"
    } @args 
} -PassThru

# You should now call $x.Test("Hello World")
# But if you call $x.Test() it will prompt you for the $message value