PoshCode Archive  Artifact [708c128e79]

Artifact 708c128e790e98212a719c980e4ce29f77364b7e22ef7b11339a3c0a6838c6ba:

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

# 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: 3718
# x-archived: 2012-10-30T23:30:49
# x-published: 2012-10-29T10:51:00
#
#
$x = New-Object PSObject | 
      Add-Member -MemberType ScriptMethod -Name Test -Value {
          param($message=$(Read-Host "Message")) 
          return "This is the message: $message"
      } -Passthru

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