# encoding: ascii
# api: powershell
# title: Get-Arguments.ps1
# description: From Windows PowerShell Cookbook (O’Reilly) by Lee Holmes
# version: 4.5
# type: function
# author: Lee Holmes
# license: CC0
# x-poshcode-id: 2148
# x-archived: 2016-05-17T13:49:02
# x-published: 2011-09-09T21:40:00
#
#
##############################################################################
##
## Get-Arguments
##
## From Windows PowerShell Cookbook (O'Reilly)
## by Lee Holmes (http://www.leeholmes.com/guide)
##
##############################################################################
<#
.SYNOPSIS
Uses command-line arguments
#>
param(
## The first named argument
$FirstNamedArgument,
## The second named argument
[int] $SecondNamedArgument = 0
)
Set-StrictMode -Version Latest
## Display the arguments by name
"First named argument is: $firstNamedArgument"
"Second named argument is: $secondNamedArgument"
function GetArgumentsFunction
{
## We could use a param statement here, as well
## param($firstNamedArgument, [int] $secondNamedArgument = 0)
## Display the arguments by position
"First positional function argument is: " + $args[0]
"Second positional function argument is: " + $args[1]
}
GetArgumentsFunction One Two
$scriptBlock =
{
param($firstNamedArgument, [int] $secondNamedArgument = 0)
## We could use $args here, as well
"First named scriptblock argument is: $firstNamedArgument"
"Second named scriptblock argument is: $secondNamedArgument"
}
& $scriptBlock -First One -Second 4.5