conditions when getting parameters

I have the parameters as followed

[CmdletBinding()]



param

(



[

Parameter(Mandatory=$True,Position=1)]

[

String]$src,

[

Parameter(Mandatory=$True,Position=2)]

[

String]$destsite,

[

Parameter(Mandatory=$True,Position=3)]

[

String]$destlib,

[

Parameter(Mandatory=$True,Position=4)]

[

String]$exclusions,

[

Parameter(Mandatory=$True,Position=5)]

[

String]$permissionmap,

[

Parameter(Mandatory=$False,Position=6)]

[

String]$batch,

[

Parameter(Mandatory=$True,Position=7)]

[

Int]$quota,

[

Parameter(Mandatory=$False,Position=8)]

[

Switch]$dryrun,

[

Parameter(Mandatory=$False,Position=9)]

[

Switch]$copy


)

What I am wanting to do is, if batch is there src, destsite and destlib are no longer necessary

also if any of the parameters are spelt wrong like -cpy then I can put my own error message in 

July 9th, 2015 9:20am

What you want is called ParameterSets.

Use Parameter Sets to Simplify PowerShell Commands

Free Windows Admin Tool Kit Click here and download it now
July 9th, 2015 9:28am

What you want is called ParameterSets.

Use Parameter Sets to Simplify PowerShell Commands

July 9th, 2015 9:34am

What you want is called ParameterSets.

Use Parameter Sets to Simplify PowerShell Commands

  • Edited by Leif-Arne Helland Thursday, July 09, 2015 1:26 PM
  • Proposed as answer by Mike Laughlin Thursday, July 09, 2015 2:46 PM
  • Unproposed as answer by bended 22 hours 40 minutes ago
  • Marked as answer by bended 22 hours 34 minutes ago
Free Windows Admin Tool Kit Click here and download it now
July 9th, 2015 1:23pm

What you want is called ParameterSets.

Use Parameter Sets to Simplify PowerShell Commands

  • Edited by Leif-Arne Helland Thursday, July 09, 2015 1:26 PM
  • Proposed as answer by Mike Laughlin Thursday, July 09, 2015 2:46 PM
  • Unproposed as answer by bended Friday, July 10, 2015 8:28 AM
  • Marked as answer by bended Friday, July 10, 2015 8:35 AM
July 9th, 2015 1:23pm

Please don't post colorized text from IDE as it is impossible to read in most browsers.

Free Windows Admin Tool Kit Click here and download it now
July 9th, 2015 2:51pm

I have reformatted your code for readability

[CmdletBinding()]
param
(
  [Parameter(Mandatory=$True, Position=1)] [String] $src,
  [Parameter(Mandatory=$True, Position=2)] [String] $destsite,
  [Parameter(Mandatory=$True, Position=3)] [String] $destlib,
  [Parameter(Mandatory=$True, Position=4)] [String] $exclusions,
  [Parameter(Mandatory=$True, Position=5)] [String] $permissionmap,
  [Parameter(Mandatory=$False,Position=6)] [String] $batch,
  [Parameter(Mandatory=$True, Position=7)] [Int]    $quota,
  [Parameter(Mandatory=$False,Position=8)] [Switch] $dryrun,
  [Parameter(Mandatory=$False,Position=9)] [Switch] $copy
)


  • Edited by Larry Weiss 7 hours 44 minutes ago copyedit
July 9th, 2015 4:06pm

I have reformatted your code for readability

[CmdletBinding()]
param
(
  [Parameter(Mandatory=$True, Position=1)] [String] $src,
  [Parameter(Mandatory=$True, Position=2)] [String] $destsite,
  [Parameter(Mandatory=$True, Position=3)] [String] $destlib,
  [Parameter(Mandatory=$True, Position=4)] [String] $exclusions,
  [Parameter(Mandatory=$True, Position=5)] [String] $permissionmap,
  [Parameter(Mandatory=$False,Position=6)] [String] $batch,
  [Parameter(Mandatory=$True, Position=7)] [Int]    $quota,
  [Parameter(Mandatory=$False,Position=8)] [Switch] $dryrun,
  [Parameter(Mandatory=$False,Position=9)] [Switch] $copy
)


  • Edited by Larry Weiss 7 hours 38 minutes ago copyedit
Free Windows Admin Tool Kit Click here and download it now
July 9th, 2015 4:12pm

Your question is still too vague.  Can you read what you asked and write it in complete sentences.  Maybe you typo-ed some of it.
July 9th, 2015 6:53pm

I wonder if that was a sufficient answer for the OP ?

The one issue that was asked that I don't relate to ParameterSets is the discovery of misspelled parameters and the way to code a specialized diagnostic when they are discovered.
Free Windows Admin Tool Kit Click here and download it now
July 9th, 2015 7:46pm

I have reformatted your code for readability

[CmdletBinding()]
param
(
  [Parameter(Mandatory=$True, Position=1)] [String] $src,
  [Parameter(Mandatory=$True, Position=2)] [String] $destsite,
  [Parameter(Mandatory=$True, Position=3)] [String] $destlib,
  [Parameter(Mandatory=$True, Position=4)] [String] $exclusions,
  [Parameter(Mandatory=$True, Position=5)] [String] $permissionmap,
  [Parameter(Mandatory=$False,Position=6)] [String] $batch,
  [Parameter(Mandatory=$True, Position=7)] [Int]    $quota,
  [Parameter(Mandatory=$False,Position=8)] [Switch] $dryrun,
  [Parameter(Mandatory=$False,Position=9)] [Switch] $copy
)


  • Edited by Larry Weiss Thursday, July 09, 2015 11:25 PM copyedit
July 9th, 2015 8:01pm

I have reformatted your code for readability

[CmdletBinding()]
param
(
  [Parameter(Mandatory=$True, Position=1)] [String] $src,
  [Parameter(Mandatory=$True, Position=2)] [String] $destsite,
  [Parameter(Mandatory=$True, Position=3)] [String] $destlib,
  [Parameter(Mandatory=$True, Position=4)] [String] $exclusions,
  [Parameter(Mandatory=$True, Position=5)] [String] $permissionmap,
  [Parameter(Mandatory=$False,Position=6)] [String] $batch,
  [Parameter(Mandatory=$True, Position=7)] [Int]    $quota,
  [Parameter(Mandatory=$False,Position=8)] [Switch] $dryrun,
  [Parameter(Mandatory=$False,Position=9)] [Switch] $copy
)


  • Edited by Larry Weiss Thursday, July 09, 2015 11:25 PM copyedit
Free Windows Admin Tool Kit Click here and download it now
July 9th, 2015 8:01pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics