function Test-Params {
[CmdletBinding(DefaultParameterSetName='FilesOnly')]
param(
[Parameter(
ParameterSetName='Optionals',
Mandatory=$true
)]
[String]
$Optional1 ,
[Parameter(
ParameterSetName='Optionals',
Mandatory=$true
)]
[String]
$Optional2 ,
[Parameter(
ParameterSetName='FilesOnly',
Mandatory=$true,
ValueFromRemainingArguments=$true,,
Position=0
)]
[Parameter(
ParameterSetName='Optionals',
Mandatory=$true,
ValueFromRemainingArguments=$true,
Position=2
)]
[String[]]
$Files
)
"Op1: $Optional1"
"Op2: $Optional2"
"Files: $Files"
"File Count: $($Files.Count)"
}
Get-Help Test-Params
Test-Params 'C:\Windows','C:\Temp'
Test-Params -Optional1 'a' -Optional2 'b' 'C:\Users','C:\eclipse'
Test-Params C:\Windows C:\users C:\temp
Test-Params -Optional1 'a' -Optional2 'b' C:\Windows C:\users C:\temp
Try to run this, it should shed some light on how you can do this with parameter sets.
It wasn't clear to me whether the optional parameters needed to be specified together or not, so I assumed yes.
If not, then it could still be achieved, but the code will be longer. Let me know!
Added the ValueFromRemainingArguments attribute so that you don't have to format the files as an array, since that seemed to be the way you were calling it in the example.