PowerShell for Windows Admins

May 5 2013   4:30PM GMT

Scripting games–using parameters

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

I am seeing an incredible number of scripts that have this sort of coding round parameters

# Input from the user
[Parameter(Mandatory=$false,
ValueFromPipeline=$False,
Position=0)]
[ValidateScript({Test-Path $_ })]
[String]$SourcePath = ‘C:\Application\Log’,

[Parameter(Mandatory=$false,
ValueFromPipeline=$False,
Position=1)]
[ValidateScript({Test-Path $_ })]
[String]$ArchivePath = ‘\\NASServer\Archives’,

[Parameter(Mandatory=$false,
ValueFromPipeline=$False,
Position=2)]
[Int]$Days = 90

Why do you need to state that Mandatory=$false or that ValueFromPipeline=$False. The DEFAULT values are false. You only need to use them if you are setting them to TRUE.

Its a waste of coding time and processing time when you run the script.

I remember blogging about this last year.

Please stop doing it so I don’t have to blog about it next year

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: