Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Create an Optional ParameterSet with Two Mandatory Parameters

$
0
0

My goal is to end up with a syntax that looks like this:

Cmdlet [[-ReportStart] <DateTime> [-ReportEnd] <DateTime>] [<CommonParameters>]

The idea is that the Cmdlet can be run either with 0 or 2 parameters.  If you specify ReportStart or ReportEnd, you must specify the other.  If you specify neither, then the Cmdlet will use default values.

This is what I have so far, but this doesn't make the ReportDate set optional.

[CmdletBinding(SupportsShouldProcess=$False)]
Param(
	[Parameter(ParameterSetName="ReportDate",
			   Mandatory=$true,
			   Position=0,
			   ValueFromPipeline=$false)]
	[ValidateNotNullOrEmpty()]
	[DateTime]
	$ReportStart,

	[Parameter(ParameterSetName="ReportDate",
			   Mandatory=$true,
			   Position=1,
			   ValueFromPipeline=$false)]
	[ValidateNotNullOrEmpty()]
	[DateTime]
	$ReportEnd
)
Any help is greatly appreciated!


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>