首页 > 技术文章 > Powershell实战之脚本参数

mowl 2018-07-19 15:08 原文

在Powershell的脚本中,可以使用自定义的参数列表,通常将参数放在Param()中

[Cmdletbinding()]
param(
[Parameter(Mandatory=$True)]
[Alias('DT')]
[ValidateSet(2,3)]
[int]DiskType
)

Mandatory设置为True,表示该参数强制输入

Alias是为该参数设置了一个别名

ValidateSet是为该参数设置了一个可用值列表

 

同时在脚本中使用write-verbose输出详细信息,在运行脚本的时候可以使用-verbose就能输出相关信息

推荐阅读