在 PowerShell 中,在声明字符串数组参数时,是否可以使用 Test-Path(或其他东西)来验证多个文件 [英] In PowerShell, can Test-Path (or something else) be used to validate multiple files when declaring a string array parameter

查看:49
本文介绍了在 PowerShell 中,在声明字符串数组参数时,是否可以使用 Test-Path(或其他东西)来验证多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个函数接受文件的字符串数组参数,我想使用 Test-Path(或其他东西)来确保字符串数组参数中的所有文件都存在.如果可能,我想在参数声明中执行此操作.

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 parameter exists. I would like to do this in the parameter declaration if possible.

这可能吗?

推荐答案

可以使用 ValidateScript

You can use ValidateScript

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

有关参数验证的更多文档,请访问 about_Functions_Advanced_Parameters

For more documentation on parameter validation visit about_Functions_Advanced_Parameters

这篇关于在 PowerShell 中,在声明字符串数组参数时,是否可以使用 Test-Path(或其他东西)来验证多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆