I have a code in my function that works well for me, was inspired by another SO answer, but is marked as improper in VSCode. I would like to improve on it, but currently I have no idea how.
Param(
[Parameter( Mandatory = $True,
ValueFromPipelineByPropertyName = $true,
Position = 0,
ParameterSetName = "Info")]
[switch] $Info = $false,
[Parameter( Mandatory = $True,
ValueFromPipelineByPropertyName = $true,
Position = 0,
ParameterSetName = "Warn")]
[switch] $Warn = $false,
[Parameter( Mandatory = $True,
ValueFromPipelineByPropertyName = $true,
Position = 0,
ParameterSetName = "Error")]
[switch] $Error = $false,
[Parameter( Mandatory = $True,
ValueFromPipelineByPropertyName = $true,
Position = 0,
ParameterSetName = "Fatal")]
[switch] $Fatal = $false,
[Parameter( Mandatory = $True,
ValueFromPipelineByPropertyName = $true,
Position = 0,
ParameterSetName = "Debug")]
[switch] $Debugging = $false,
)
switch ($PSBoundParameters.Keys) {
'Info' { $level = "INFO"
$color = "Green" }
'Warn' { $level = "WARNING"
$color = "Yellow" }
'Error' { $level = "ERROR"
$color = "Red" }
'Fatal' { $level = "FATAL"
$color = "DarkRed" }
'Debugging' { $level = "DEBUG"
$color = "Magenta" }
}
The error is https://github.com/PowerShell/PSScriptAnalyzer/blob/master/RuleDocumentation/AvoidDefaultValueForMandatoryParameter.md - I get that, but how to transform this code so that it is kosher and still performs the same function?
PSSA complains because the Mandatory flag applies to the user - the user must specify arguments for all parameters marked Mandatory in a parameter set - and since the user is already required to supply arguments, it makes no sense to default values, PowerShell will never use them.
The local variables corresponding to the switch parameters in the parameter sets NOT chosen will default to a $null-like value, equivalent to $false anyway:
Param(
[Parameter( Mandatory = $True,
ValueFromPipelineByPropertyName = $true,
Position = 0,
ParameterSetName = "Info")]
[switch] $Info,
[Parameter( Mandatory = $True,
ValueFromPipelineByPropertyName = $true,
Position = 0,
ParameterSetName = "Warn")]
[switch] $Warn,
[Parameter( Mandatory = $True,
ValueFromPipelineByPropertyName = $true,
Position = 0,
ParameterSetName = "Error")]
[switch] $Error,
[Parameter( Mandatory = $True,
ValueFromPipelineByPropertyName = $true,
Position = 0,
ParameterSetName = "Fatal")]
[switch] $Fatal,
[Parameter( Mandatory = $True,
ValueFromPipelineByPropertyName = $true,
Position = 0,
ParameterSetName = "Debug")]
[switch] $Debugging,
)
Related
I have a function that have this parameters:
param (
[Parameter (Mandatory = $false,
ParameterSetName = "SendMail",
HelpMessage = "Call this parameter to send information mail ONLY.")]
[switch]$SendMail,
[Parameter (Mandatory = $false,
Position = 0,
ParameterSetName = "UseRegion",
HelpMessage = "Call this parameter to use the function with Regions.")]
[Parameter (Mandatory = $false,
ParameterSetName = "UseCountry")]
[switch]$UseRegions,
[Parameter (Mandatory = $false,
ParameterSetName = "SendMail")]
[Parameter (Mandatory = $true,
ParameterSetName = "UseRegion",
HelpMessage = "Define the region to apply the function.")]
[ValidateSet("AMER","APAC","EMEA")]
[string]$Region,
[Parameter (Mandatory = $false,
ParameterSetName = "SendMail")]
[Parameter (Mandatory = $false,
ParameterSetName = "UseRegion")]
[Parameter (Mandatory = $true,
HelpMessage = "Define the country to apply the function.",
ParameterSetName = "UseCountry")]
[ValidateNotNullOrEmpty()]
[string]$Country,
[Parameter (Mandatory = $false,
HelpMessage = "Define months for a machine to be outdated. Default value is 3.")]
[ValidateRange(1, [int]::MaxValue)]
[int]$Months = 3,
[Parameter (Mandatory = $false,
HelpMessage = "Define days for a machine to be on the ""Disabled"" OU before permanent deletion. Minimum and default value is 7.")]
[ValidateRange([int] 7, [int] 30)]
[int]$DaysToDeletion = 7,
[Parameter (Mandatory = $false,
HelpMessage = "Define operation to exclude from the rule. I.E.: Operations that does not connect to the VPN.")]
[string]$Exclude
)
i'm trying to acomplish the following:
When i call -SendMail NO parameter is mandatory
When i call -UseRegions, -Region is mandatory and the rest is not.
When i don't call -UseRegions, -Country is mandatory and the rest is not.
I've been playing with parameter sets but i can never get it to resolve.
I also don't want to have an extra parameter called -UseCountry, i want -UseRegions to controll both -Region and -Country.
Anyone had anything like it?
Thanks a lot in advance!!!!
I get it, parameter sets make even my head spin sometimes. What it sounds like, is that you want 3 different sets.
Country
Region
SendMail
You can remove all but the -SendMail switch by using mandatory = $true.
function potato
{
param (
[Parameter (
Mandatory = $true,
ParameterSetName = "SendMail",
HelpMessage = "Call this parameter to send information mail ONLY."
)]
[Parameter (
Mandatory = $false,
ParameterSetName = "UseRegion"
)]
[Parameter (
Mandatory = $false,
ParameterSetName = "UseCountry"
)]
[switch]
$SendMail,
[Parameter (
Mandatory = $false,
ParameterSetName = "SendMail"
)]
[Parameter (
Mandatory = $true,
ParameterSetName = "UseRegion",
HelpMessage = "Define the region to apply the function."
)]
[Parameter (
Mandatory = $false,
ParameterSetName = "UseCountry"
)]
[ValidateSet("AMER","APAC","EMEA")]
[string]
$Region,
[Parameter (
Mandatory = $false,
ParameterSetName = "SendMail"
)]
[Parameter (
Mandatory = $false,
ParameterSetName = "UseRegion"
)]
[Parameter (
Mandatory = $true,
HelpMessage = "Define the country to apply the function.",
ParameterSetName = "UseCountry"
)]
[ValidateNotNullOrEmpty()]
[string]
$Country,
[Parameter (
Mandatory = $false,
ParameterSetName = "SendMail"
)]
[Parameter (
Mandatory = $false,
ParameterSetName = "UseRegion"
)]
[Parameter (
Mandatory = $false,
ParameterSetName = "UseCountry"
)]
[Parameter (
Mandatory = $false,
HelpMessage = "Define months for a machine to be outdated. Default value is 3."
)]
[ValidateRange(1, [int]::MaxValue)]
[int]
$Months = 3,
[Parameter (
Mandatory = $false,
ParameterSetName = "SendMail"
)]
[Parameter (
Mandatory = $false,
ParameterSetName = "UseRegion"
)]
[Parameter (
Mandatory = $false,
ParameterSetName = "UseCountry"
)]
[Parameter (
Mandatory = $false,
HelpMessage = "Define days for a machine to be on the ""Disabled"" OU before permanent deletion. Minimum and default value is 7."
)]
[ValidateRange([int] 7, [int] 30)]
[int]
$DaysToDeletion = 7,
[Parameter (
Mandatory = $false,
ParameterSetName = "SendMail"
)]
[Parameter (
Mandatory = $false,
ParameterSetName = "UseRegion"
)]
[Parameter (
Mandatory = $false,
ParameterSetName = "UseCountry"
)]
[Parameter (
Mandatory = $false,
HelpMessage = "Define operation to exclude from the rule. I.E.: Operations that does not connect to the VPN."
)]
[string]
$Exclude
)
}
Now if you do a help potato the SYNTAX section will show this
potato -Country <string> [-SendMail] [-Region {AMER | APAC | EMEA}] [-Months <int>] [-
DaysToDeletion <int>] [-Exclude <string>] [<CommonParameters>]
potato -Region {AMER | APAC | EMEA} [-SendMail] [-Country <string>] [-Months <int>] [-
DaysToDeletion <int>] [-Exclude <string>] [<CommonParameters>]
potato -SendMail [-Region {AMER | APAC | EMEA}] [-Country <string>] [-Months <int>] [-
DaysToDeletion <int>] [-Exclude <string>] [<CommonParameters>]
I am new on Powershell
I parameterise the below variables in Powershell.
$accountName = "abc"
$container = "test"
$rootDir = "Folder1"
$absoluteAcl = "user:mary#contoso.com:rwx,default:user:mary#contoso.com:rwx"
So i used the below code to parameterise above variable.
param(
[Parameter(Mandatory = $true, HelpMessage = "")]
[string]$accountName1 = $accountName,
[Parameter(Mandatory = $true, HelpMessage = "")]
[string]$container1 = $container,
[Parameter(Mandatory = $true, HelpMessage = "")]
[string]$rootDir1 = $rootDir,
[Parameter(Mandatory = $true, HelpMessage = "")]
[string]$userinput1 = $absoluteAcl,
When i input the value of $userinput1 = user:mary#contoso.com:rwx,default:user:mary#contoso.com:rwx
My script break due to string value
How I can pass this string = user:mary#contoso.com:rwx,default:user:mary#contoso.com:rwx as a parameterise value.
I have tried below option
"user:mary#contoso.com:rwx,default:user:mary#contoso.com:rwx"
"user:mary#contoso.com:rwx","default:user:mary#contoso.com:rwx"
None of them is working.
Pass them as a string array:
$accountName = "abc"
$container = "test"
$rootDir = "Folder1"
$absoluteAcl = "user:mary#contoso.com:rwx","default:user:mary#contoso.com:rwx"
# So i used the below code to parameterise above variable.
param(
[Parameter(Mandatory = $true, HelpMessage = "")]
[string]$accountName1 = $accountName,
[Parameter(Mandatory = $true, HelpMessage = "")]
[string]$container1 = $container,
[Parameter(Mandatory = $true, HelpMessage = "")]
[string]$rootDir1 = $rootDir,
[Parameter(Mandatory = $true, HelpMessage = "")]
[string[]]$userinput1 = $absoluteAcl,
string[] means to accept an comma separated array of strings. I have also changed $absoluteAcl to fit your needs.
I'm doing something that seems pretty basic to me but is not working as expected.
If the script is run with the -WhatIf switch then $liveTest should be "Test".
If the script is run with the -Live switch then $liveTest should be "Live".
However both switches are causing $liveTest to be "Test"
param (
[CmdletBinding()]
[Parameter(Mandatory = $true, ParameterSetName = 'UsersOnlyLive')]
[Parameter(Mandatory = $true, ParameterSetName = 'UsersOnlyTest')]
[Switch]
$users,
[Parameter(Mandatory = $true, ParameterSetName = 'ComputersOnlyLive')]
[Parameter(Mandatory = $true, ParameterSetName = 'ComputersOnlyTest')]
[Switch]
$computers,
[Parameter(Mandatory = $true, ParameterSetName = 'AllLive')]
[Parameter(Mandatory = $true, ParameterSetName = 'AllTest')]
[Switch]
$all,
[Parameter(Mandatory=$true)]
[string]
$days,
[switch]
$console,
[Parameter(Mandatory = $true, ParameterSetName = 'AllTest')]
[Parameter(Mandatory = $true, ParameterSetName = 'UsersOnlyTest')]
[Parameter(Mandatory = $true, ParameterSetName = 'ComputersOnlyTest')]
[switch]
$WhatIf,
[Parameter(Mandatory = $true, ParameterSetName = 'AllLive')]
[Parameter(Mandatory = $true, ParameterSetName = 'UsersOnlyLive')]
[Parameter(Mandatory = $true, ParameterSetName = 'ComputersOnlyLive')]
[switch]
$live
)
Process {
# If -WhatIf or -Live switch is passed, creates a hashtable for the -WhatIf parameter.
If($WhatIf) {
$whatIf = #{ WhatIf = $true }
$liveTest = "Test"
}
ElseIf($live) {
$whatIf = #{ WhatIf = $false }
$liveTest = "Live"
}
If($liveTest = "Test"){Write-Output $liveTest}
elseif($liveTest = "Live"){Write-Output $liveTest}
}
Your if and elseif conditions are using the assignment operator = rather than comparison operator -eq. As a result, $liveTest is getting set to Test on each run. Update your code to the following:
if ($liveTest -eq "Test") {
Write-Output $liveTest
}
elseif ($liveTest -eq "Live") {
Write-Output $liveTest
}
Since you are using if and elseif conditions to do variable assignment, $liveTest = "Test" always happens and $liveTest = "Live" never happens.
See About_Comparison_Operators for more information.
I have a powershell script with rather long parameter sets:
Param(
[Parameter(Position = 0, Mandatory = $true, ParameterSetName = 'Senders')]
[Parameter(Position = 0, Mandatory = $true, ParameterSetName = 'Recipients')]
[Parameter(Position = 0, Mandatory = $true, ParameterSetName = 'Global')]
[Parameter(Position = 0, Mandatory = $true, ParameterSetName = 'Manager')]
[Parameter(Position = 0, Mandatory = $true, ParameterSetName = 'CatalogueName')]
[Parameter(Position = 0, Mandatory = $true, ParameterSetName = 'ReapplyPermissions')]
[Parameter(Position = 0, Mandatory = $true, ParameterSetName = 'OnlyListing')]
[String]$SharedElement,
[Parameter(Mandatory = $true, ParameterSetName = 'Senders')]
[String]$Senders,
[Parameter(Mandatory = $false, ParameterSetName = 'Senders')]
[Parameter(Mandatory = $true, ParameterSetName = 'Recipients')]
[String]$Recipients,
[Parameter(Mandatory = $true, ParameterSetName = 'Global')]
[String]$Global,
[Parameter(Mandatory = $false, ParameterSetName = 'Senders')]
[Parameter(Mandatory = $false, ParameterSetName = 'Recipients')]
[Parameter(Mandatory = $false, ParameterSetName = 'Global')]
[Parameter(Mandatory = $true, ParameterSetName = 'Manager')]
[Alias("Owner")]
[String]$Manager,
[Parameter(Mandatory = $false, ParameterSetName = 'Senders')]
[Parameter(Mandatory = $false, ParameterSetName = 'Recipients')]
[Parameter(Mandatory = $false, ParameterSetName = 'Global')]
[Parameter(Mandatory = $false, ParameterSetName = 'Manager')]
[Parameter(Mandatory = $true, ParameterSetName = 'CatalogueName')]
[String]$CatalogueName,
[Parameter(Mandatory = $true, ParameterSetName = 'ReapplyPermissions')]
[Switch]$ReapplyPermissions,
[Parameter(Mandatory = $true, ParameterSetName = 'OnlyListing')]
[Switch]$OnlyListing,
[Parameter(Mandatory = $false, ParameterSetName = 'Senders')]
[Parameter(Mandatory = $false, ParameterSetName = 'Recipients')]
[Parameter(Mandatory = $false, ParameterSetName = 'Global')]
[Parameter(Mandatory = $false, ParameterSetName = 'Manager')]
[Parameter(Mandatory = $false, ParameterSetName = 'CatalogueName')]
[Parameter(Mandatory = $false, ParameterSetName = 'ReapplyPermissions')]
[Parameter(Mandatory = $false, ParameterSetName = 'OnlyListing')]
[Switch]$NoLog,
[Parameter(Mandatory = $false, ParameterSetName = 'Senders')]
[Parameter(Mandatory = $false, ParameterSetName = 'Recipients')]
[Parameter(Mandatory = $false, ParameterSetName = 'Global')]
[Parameter(Mandatory = $false, ParameterSetName = 'Manager')]
[Parameter(Mandatory = $false, ParameterSetName = 'CatalogueName')]
[Parameter(Mandatory = $false, ParameterSetName = 'ReapplyPermissions')]
[Parameter(Mandatory = $false, ParameterSetName = 'OnlyListing')]
[String]$Reference,
[Parameter(Mandatory = $false, ParameterSetName = 'Senders')]
[Parameter(Mandatory = $false, ParameterSetName = 'Recipients')]
[Parameter(Mandatory = $false, ParameterSetName = 'Global')]
[Parameter(Mandatory = $false, ParameterSetName = 'Manager')]
[Parameter(Mandatory = $false, ParameterSetName = 'CatalogueName')]
[Parameter(Mandatory = $false, ParameterSetName = 'ReapplyPermissions')]
[Parameter(Mandatory = $false, ParameterSetName = 'OnlyListing')]
[Switch]$AskCredentials,
[Parameter(Mandatory = $true, ParameterSetName = 'Help')]
[Switch]$Help
)
I have tested the functionality of these parameters according to my needs and it works fine except in one particular case: when I run the script with parameters SharedElement, OnlyListing and Reference
script.ps1 -SharedElement email.address#domain.com -OnlyListing -Reference "Some string"
I always get an error:
Parameter set cannot be resolved using the specified named parameters
However when I run the script with parameters SharedElement, OnlyListing and NoLog it works fine:
script.ps1 -SharedElement email.address#domain.com -OnlyListing -NoLog
I have been wondering for months what the problem could be and I haven't been able to find a solution. Can anyone point a hint to help me to resolve the problem?
Thank you very much in advance.
Regards.
After the first comment I copied the code from this web page, pasted it into my script and it worked fine. I compared the script with the previous version in my SVN repository and there was a difference in the parameter set name "OnlyListing" applied to the $Reference parameter. Apparently both parameter set names were identical but one of them contained a hidden character.
Thank you everybody for the help.
This is somewhat related to a question I asked earlier; Group parameter (set?) requiring one of the parameters
I have a set of 5 parameters; Years, Months, Days, Path, Input. I'm looking to combine parameter sets so that I can have the following combinations;
Years & (Path or Input)
Months & (Path or Input)
Days & (Path or Input)
Path is a typed path and Input is a pointer to a file, either way, one of them is required.
I've tried
[Parameter(Mandatory = $true, ParameterSetName = 'Path')]
[Parameter(Mandatory = $true, ParameterSetName = 'Input')
[int]$Years = '7'
But Path & Input are required if using Years
Param (
[parameter(Position = 0, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)]
[string[]]$Filter = '*.*',
[Parameter(Mandatory = $True, ParameterSetName = 'ByYears')]
[int]$Years = '7',
[Parameter(Mandatory = $True, ParameterSetName = 'ByMonths')]
[int]$Months,
[Parameter(Mandatory = $True, ParameterSetName = 'ByDay')]
[int]$Days,
[Parameter(Mandatory = $true, ParameterSetName = 'Path')]
[string[]]$Path,
[Parameter(Mandatory = $true, ParameterSetName = 'Input')]
[string]$Input,
[switch]$Recurse,
[Parameter(Mandatory = $true)]
[string]$ReportPath = $PWD
)
In the end I'm looking to have the possibility of only one of the combinations below;
-Years 2 -Path C:\Temp
-Years 2 -Input C:\Temp\file.txt
-Months 2 -Path C:\Temp
-Months 2 -Input C:\Temp\file.txt
-Days 2 -Path C:\Temp
-Days 2 -Input C:\Temp\file.txt
There's no way of directly expressing ParameterA and (ParameterB or ParameterC) in ParameterSets but you can create two ParameterSets: ParameterA and ParameterB and ParameterA and ParameterC which does the same thing.
If you extend that to your scenario, you'll need 6 ParameterSets:
YearsAndPath
YearsAndInput
MonthsAndPath
MonthsAndInput
DaysAndPath
DaysAndInput
And then you just tag each parameter with the ParameterSets it needs to be used in, and your param block becomes something like:
function Invoke-Params
{
param(
[parameter(Position = 0, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)]
[string[]]$Filter = '*.*',
[Parameter(Mandatory = $True, ParameterSetName = 'YearsAndPath')]
[Parameter(Mandatory = $True, ParameterSetName = 'YearsAndInput')]
[int]$Years = '7',
[Parameter(Mandatory = $True, ParameterSetName = 'MonthsAndPath')]
[Parameter(Mandatory = $True, ParameterSetName = 'MonthsAndInput')]
[int]$Months,
[Parameter(Mandatory = $True, ParameterSetName = 'DaysAndPath')]
[Parameter(Mandatory = $True, ParameterSetName = 'DaysAndInput')]
[int]$Days,
[Parameter(Mandatory = $true, ParameterSetName = 'YearsAndPath')]
[Parameter(Mandatory = $true, ParameterSetName = 'MonthsAndPath')]
[Parameter(Mandatory = $true, ParameterSetName = 'DaysAndPath')]
[string[]]$Path,
[Parameter(Mandatory = $true, ParameterSetName = 'YearsAndInput')]
[Parameter(Mandatory = $true, ParameterSetName = 'MonthsAndInput')]
[Parameter(Mandatory = $true, ParameterSetName = 'DaysAndInput')]
[string]$Input,
[switch]$Recurse,
[Parameter(Mandatory = $true)]
[string]$ReportPath = $PWD
)
}
The following then work fine:
PS> Invoke-Params -Years 5 -Path "xxx"
PS> Invoke-Params -Years 5 -Input "xxx"
and these throw an exception:
PS> Invoke-Params -Years 5
Invoke-Params : Parameter set cannot be resolved using the specified named parameters.
At line:1 char:1
+ Invoke-Params -Years 5
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Invoke-Params], ParameterBindingException
+ FullyQualifiedErrorId : AmbiguousParameterSet,Invoke-Params
PS> Invoke-Params -Years 5 -Path "aaa" -Input "bbb"
Invoke-Params : Parameter set cannot be resolved using the specified named parameters.
At line:1 char:1
+ Invoke-Params -Years 5 -Path "aaa" -Input "bbb"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Invoke-Params], ParameterBindingException
+ FullyQualifiedErrorId : AmbiguousParameterSet,Invoke-Params
The answer by mclayton is correct in that you would have to use 6 parameter set names.
There are three 'time' parameters that should rule each other out and must be used together with either one of two 'path' parameters.
However, you should not use $input as parameter, since this is an Automatic variable as Mathias R. Jessen already commented, and because you are setting up the $Years parameter with a default value, Mandatory should be $false on that one.
Because using combinations of parameter sets is always a puzzle, I would put the parameters in a more logical order (at least to me..) by first defining the two 'path' parameters and setting the DefaultParameterSetName to be the first of those.
By also adding Position = 0 on that first parameter, you can call the function with just the path without having to name it.
Just play around with the function below to see what combinations are possible and what the function will use:
function Show-Parameters {
[CmdletBinding(DefaultParameterSetName = 'ByFolderYears')]
param (
[Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true, ParameterSetName = 'ByFolderYears')]
[Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true, ParameterSetName = 'ByFolderMonths')]
[Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true, ParameterSetName = 'ByFolderDays')]
[Alias('Path')]
[string[]]$FolderPath,
[Parameter(Mandatory = $true, ParameterSetName = 'ByFileYears')]
[Parameter(Mandatory = $true, ParameterSetName = 'ByFileMonths')]
[Parameter(Mandatory = $true, ParameterSetName = 'ByFileDays')]
[Alias('File')]
[string]$FilePath,
[Parameter(Mandatory = $false, ParameterSetName = 'ByFolderYears')]
[Parameter(Mandatory = $false, ParameterSetName = 'ByFileYears')]
[int]$Years = 7,
[Parameter(Mandatory = $true, ParameterSetName = 'ByFolderMonths')]
[Parameter(Mandatory = $true, ParameterSetName = 'ByFileMonths')]
[int]$Months,
[Parameter(Mandatory = $true, ParameterSetName = 'ByFolderDays')]
[Parameter(Mandatory = $true, ParameterSetName = 'ByFileDays')]
[int]$Days,
[string[]]$Filter = '*.*',
[string]$ReportPath = $PWD,
[switch]$Recurse
)
# just to show what parameter the function will use
$paramsUsed = [ordered]#{}
$paramSet = $PSCmdlet.ParameterSetName
if ($paramSet.StartsWith('ByFolder')) { $paramsUsed['FolderPath'] = $FolderPath -join '; ' }
else {$paramsUsed['FilePath'] = $FilePath}
if ($paramSet.EndsWith('Years')) { $paramsUsed['Years'] = $Years }
elseif ($paramSet.EndsWith('Months')) { $paramsUsed['Months'] = $Months }
else { $paramsUsed['Days'] = $Days }
if ($Filter) { $paramsUsed['Filter'] = $Filter -join '; ' }
if ($ReportPath) { $paramsUsed['ReportPath'] = $ReportPath }
if ($Recurse) { $paramsUsed['Recurse'] = $Recurse }
Write-Host "Using ParameterSet '$paramSet'" -ForegroundColor Cyan
$paramsUsed
}
For instance
Show-Parameters 'D:\some\path', 'Z:\some\folder'
outputs
Using ParameterSet 'ByFolderYears'
Name Value
---- -----
FolderPath D:\some\path; Z:\some\folder
Years 7
Filter *.*
ReportPath C:\Users\YourName
etc.