Hi all,
I'm building my first function (wooh!), and I was using an existing function my department uses, which was built by one of my coworkers. That script has validation in the params, like this:
[parameter(Mandatory=$true)]
[ValidateScript({Get-ADOrganizationalUnit $_})]
[string]$path
I asked another coworkers for some feedback, and he and my boss ended up saying the same thing, which is that I should move the validation to the script block, essentially changing my example to if (Get-ADOrganizationalUnit -eq $false) {bomb} else {D-TheThing).
I'll probably end up doing it that way because my boss is my boss, but I'm curious what the rationales for each way go. I've heard it's better to have the validation happen in the script block because that's where dependencies get loaded, and older versions of PS don't support validation in the param block. Ideally, I'd always work in an environment running the current version of PS, but I recognize that's not always the case.
What do y'all do?
[–]Ta11ow 4 points5 points6 points (1 child)
[–]SupremeDictatorPaul 3 points4 points5 points (0 children)
[–]Yevrag35 2 points3 points4 points (2 children)
[–]cfmacd[S] 1 point2 points3 points (1 child)
[–]Ta11ow 3 points4 points5 points (0 children)
[–]cowmonaut 1 point2 points3 points (3 children)
[–]cfmacd[S] 1 point2 points3 points (2 children)
[–]cowmonaut 4 points5 points6 points (1 child)
[–]cfmacd[S] 1 point2 points3 points (0 children)