如何在自定义脚本 cmdlet 中指定参数接受通配符 [英] How do you specify that a parameter accepts wildcard characters in a custom script cmdlet

查看:62
本文介绍了如何在自定义脚本 cmdlet 中指定参数接受通配符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当你做Get-Help SomeCommand -Full时,在每个参数下,在描述之后,还有一些额外的参数属性.这些属性之一是接受通配符?".当我为自定义脚本 cmdlet 创建帮助信息时,如何指定参数接受通配符?

When you do Get-Help SomeCommand -Full, under each parameter, after the description, there are some additional parameter properties. One of those properties is 'Accept Wildcard Characters?'. When I create my help information for a custom script cmdlet how do I specify that a parameter accepts wildcards?

推荐答案

如果您希望能够做到这一点,需要做一些事情.首先,您要么必须创建一个 .dll 文件,但您没有这样做,您必须创建一个模块.我不会详细介绍创建模块的所有细节,互联网上已经有很多关于如何做到这一点的精心编写的指南,您可以去查找.

If you want to be able to do this it will require a few things. First off, you either have to create a .dll file, which you are not doing, or you have to create a module. I am not going to go into all of the ins and outs of creating a module, there are already many well written guides on how to do that out there on the internet that you can go look up.

作为模块的一部分,您可以包含提供帮助信息的 .XML 文件,类似于单个脚本可用的注释帮助.XML 样式确实有一些优点,例如一致性和一些高级功能,但确实需要更多的努力.为此,我强烈建议阅读 Writing Help for WindowsPowerShell 模块,因为它将解释放置 XML 文件的位置、如何构建它们,以及所需的标头以及不需要的标头.

As a part of your module you can include .XML files that provide Help information similarly to the commented help available for individual scripts. The XML style does have some advantages, such as consistency and some advanced features, but does require more effort. Towards this end I would strongly suggest reading Writing Help for Windows PowerShell Modules, as it will explain where to place your XML files, how to structure them, and required headers and what not.

如果是我,我可能会复制现有的 XML 帮助文件并对其进行编辑以满足我对 cmdlet 的需求,找到并阅读其中一篇关于创建模块的简明教程,然后放弃这个想法是因为如果这一切都只是作为带有注释帮助的基本脚本开始,那么仅仅添加支持通配符"标志(在我看来)是不值得的.

If it were me I'd probably copy an existing XML help file and edit it to suit my needs for the cmdlet, find and read one of the quick-and-dirty HowTo's about creating a module, and then give up on the idea since it's not worth the effort involved to just add that 'Supports Wildcards' flag (in my opinion) if this all started out just as a basic script with commented help.

但答案是,为您的 cmdlet 创建一个模块和支持基于 XML 的帮助文件.有了它,您可以为参数添加对 Accepts Wildcards 标志的支持.

But the answer is, create a module and supporting XML based Help file for your cmdlet. With that you can add support for the Accepts Wildcards flag for your parameters.

这篇关于如何在自定义脚本 cmdlet 中指定参数接受通配符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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