1 [CmdletBinding()]
2 param(
3 [Parameter(Mandatory = $True)]
4 [string]
5 $ArgString,
6
7 [Parameter(Mandatory = $False)]
8 [Int32] # aka [Int]
9 $ArgInt32,
10
11 [Parameter(Mandatory = $False)]
12 [Float] # aka [Single]
13 $ArgFloat,
14
15 [Parameter(Mandatory = $False)]
16 [Hashtable]
17 $ArgHashtable,
18
19 [Parameter(Mandatory = $False)]
20 [Array]
21 $ArgArray,
22
23 [Parameter(Mandatory = $False)]
24 [Hashtable[]] # any array of type[] should work
25 $ArgArrayOfHashes,
26
27 [Parameter(Mandatory = $False)]
28 [IO.FileInfo] # aka a file path
29 $ArgFileInfo,
30
31 [Parameter(Mandatory = $False)]
32 [Bool]
33 $ArgBool,
34
35 [Parameter(Mandatory = $False)]
36 [TimeSpan]
37 $ArgTimeSpan,
38
39 [Parameter(Mandatory = $False)]
40 [Guid]
41 $ArgGuid,
42
43 [Parameter(Mandatory = $False)]
44 [Regex]
45 $ArgRegex,
46
47 [Parameter(Mandatory = $False)]
48 [Switch]
49 $ArgSwitch,
50
51 # Parameters may have the string `type` in them, but not have the name `type`
52 [Parameter(Mandatory = $False)]
53 [String]
54 $types
55 )
56
ConvertTo-Stringnull57 function ConvertTo-String
58 {
59 [CmdletBinding()]
60 param(
61 [Parameter(Mandatory = $True, ValueFromPipeline = $True)]
62 $Object
63 )
64
65 begin
66 {
67 $outputs = @()
68 }
69 process
70 {
71 if ($Object -is [Hashtable])
72 {
73 $outputs += (HashtableTo-String $Object)
74 }
75 else
76 {
77 $outputs += $Object
78 }
79 }
80 end
81 {
82 $outputs -join "`n"
83 }
84 }
85
HashtableTo-Stringnull86 function HashtableTo-String
87 {
88 [CmdletBinding()]
89 param(
90 [Parameter(Mandatory = $True, ValueFromPipeline = $True)]
91 [Hashtable]
92 $Hashtable
93 )
94
95 ($Hashtable.GetEnumerator() | Sort-Object -Property Key | % { "$($_.Key): $($_.Value)" }) -join "`n"
96 }
97
98 Write-Output "Defined with arguments:"
99
100 $PSCmdlet.MyInvocation.MyCommand.Parameters.GetEnumerator() | Sort-Object -Property Key | Where-Object { $_.Key -match "Arg.+" } | % {
101 Write-Output "* $($_.Key) of type $($_.Value.ParameterType)"
102 }
103
104 Write-Output "`nReceived arguments:"
105
106 $PSBoundParameters.GetEnumerator() | Sort-Object -Property Key | % {
107 Write-Output "* $($_.Key) ($($_.Value.GetType())):`n$($_.Value | ConvertTo-String)"
108 }
109