Search notes:

PowerShell parameter attribute: validateScript

The validateScript parameter attribute specifies a script block that must evaluate to $true in order for the corresponding parameter to be accepted.
Note the order: even though validateScript processes the value of the parameter (and thus logically is dependent on the parameter’s value), it must be placed before the parameter name.
The following simple script ensures that the (only) parameter $path is specified and refers to an existing directory:
param (
  [parameter     (    mandatory=$true                   )]       # make sure parameter exists
  [validateScript( { test-path -pathType container $_ } )]       # make sure path exists
  [string                                                ] $path # finally: the parameter
)

ls $path
Github repository about-PowerShell, path: /language/statement/function/parameters/attributes/validate/Script/ensure-directory.ps1

Index