You'll have to use CmdletBinding and multiple parameter sets. It's not "simple" (I would consider it "advanced PowerShell") but it does what you want.
From: Joseph L. Casale [mailto:[email protected]] Sent: Friday, April 06, 2012 12:39 PM To: NT System Admin Issues Subject: Powershell parameters Is there any shortcut to specify mandatory parameters that can be conditionaly ignored if a switch is present without a slew of following test case's and read-host code? It would be nice to pull off something like: param ( If (!($Force)) { [Parameter(Mandatory = $True)] } [string]$Path, [Switch]$Force ) Anything equally simple like this exist? Thanks! jlc ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/> ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to [email protected]<mailto:[email protected]> with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/> ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to [email protected] with the body: unsubscribe ntsysadmin
