自动完成用户输入 PowerShell 2.0 [英] Auto Complete User Input PowerShell 2.0

查看:25
本文介绍了自动完成用户输入 PowerShell 2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很大的数据列表(超过 1000 个不同的值),我希望用户能够从 PowerShell 控制台的列表中选择某些值.

I have a large list of data (over 1000 different values) and I want the user to be able to select certain values from the list from a PowerShell console.

在控制台内允许用户快速选择值的最简单方法是什么?

What is the easiest way from within the console to allow the user to quickly select values?

我想做一些诸如 tab 补全或使用箭头键滚动浏览值的能力,但我不知道如何做这些事情.

I would like to do something like tab completion or the ability to use the arrow keys to scroll through the values but I am not sure how to do either of these things.

任何建议将不胜感激.

推荐答案

PowerShell 选项卡完成可以扩展到自定义参数和参数值(在 v3 中).但是,这是高级功能的特性.您可以使用 ValidateSetAttribute 来做到这一点.

PowerShell tab completion can be extended to custom parameters and parameter values (in v3). However, this is a property of advanced functions. You can use the ValidateSetAttribute to do that.

查看有关高级功能的 Technet 帮助主题:http://technet.microsoft.com/en-我们/图书馆/hh847806.aspx

Check the Technet help topic on advanced functions: http://technet.microsoft.com/en-us/library/hh847806.aspx

您可以替换 PowerShell 中的 tabexpansion (v2) 和 tabexpansion2 (v3) 函数,以自动完成高级函数之外的参数值.您可以通过运行在 PowerShell v3 中获得对此的基本定义

You can replace the tabexpansion (v2) and tabexpansion2 (v3) function in PowerShell to auto complete parameter values outside of advanced functions. You can get a basic definition of this in PowerShell v3 by running

 Get-Content function:TabExpansion2

这是显示自定义选项卡扩展功能的示例.

Here is an example of showing custom tab expansion function.

http://www.powershellmagazine.com/2012/11/29/using-custom-argument-completers-in-powershell-3-0/

但是,如果您希望用户能够为 Read-Host 类型的输入自动完成值,您需要为 Read-Host 编写一个代理> 实现这一目标.

But, if you want to the user to be able to auto complete values for a Read-Host kind of input, you need to write a proxy for Read-Host to achieve that.

您可以选择在 http://powertab.codeplex.com/

这篇关于自动完成用户输入 PowerShell 2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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