- <#
- .SYNOPSIS
- This script contains a function, EchoArgs, that returns a list of
- the arguments passed and their type. It is used to demonstrate
- the use of the --% operator when calling a function or cmdlet, a new
- feature in PowerShell v3.
- .DESCRIPTION
- The EchoArgs function takes the arguments passed, via $args, and
- displays each argument and its type. Then, this function is called
- first with a normal calling sequence and then using --%.
- .NOTES
- File Name : EchoArgs.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN sample posted to:
- http://msdn.microsoft.com/en-us/library.
- .EXAMPLE
- Psh[Cookham8:C:\foo]>E:\PowerShellScriptLib\SERVER2012FEATURES\EchoArgs.ps1
- Calling Echoargs with 'fasdf $(LS) 2334 {asdf}'
- Argument [0]: [fasdf] Type:System.String
- Argument [1]: [System.Object[]] Type:System.Object[]
- Argument [2]: [2334] Type:System.Int32
- Argument [3]: [asdf] Type:System.Management.Automation.ScriptBlock
- Calling Echoargs with '--% asdf; {asfd}-a asdf'
- Argument [0]: [--%] Type:System.String
- Argument [1]: [asdf; $(ls) {asfd} - a asdf] Type:System.String
- #>
- # EchoArgs function
- Function EchoArgs {
- #Loop through and display each argument passed
- For ($i = 0; $i -ilt $Args.count; $i ++) {
- "Argument [{0}]: [{1}] Type:{2}" -f $I, $args[$i],$($args[$i].GetType().FullName)
- }
- }
- # Test it
- "Calling Echoargs with 'fasdf `$(LS) 2334 {asdf}'"
- Echoargs fasdf $(ls) 2334 {asdf}
- "";"Calling Echoargs with '--% asdf; {asfd}-a asdf'"
- Echoargs --% asdf; $(ls) {asfd} - a asdf
Technorati Tags: PowerShell,PowerShell V3. --% operator
No comments:
Post a Comment