# 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