In PowerShell, can Test-Path (or something else) be used to validate multiple files when declaring a string array parameter

前端 未结 3 1868
萌比男神i
萌比男神i 2021-01-11 14:18

I have a function that accepts a string array parameter of files and I would like to use Test-Path (or something else) to ensure that all the files in the string array param

3条回答
  •  既然无缘
    2021-01-11 14:38

    You can use ValidateScript

    param(
    [parameter()]
    [ValidateScript({Test-Path $_ })]
    [string[]]$paths
    )
    

    For more documentation on parameter validation visit about_Functions_Advanced_Parameters

提交回复
热议问题