Tip: The automatic variable $PSBoundParameters is a hashtable containing the parameters passed to a script or a function.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
function Test-ExtensionFile { Param ( [Parameter(Mandatory = $true)] [string[]]$Path, [switch]$Extension ) [System.IO.Path]::HasExtension($Path) if ($PSBoundParameters.ContainsKey('Extension')) { Write-Output -InputObject "Extension : $([System.IO.Path]::GetExtension($Path))" } } Test-ExtensionFile -Path 'C:\Windows\notepad.exe' -Extension |