English 中文(简体)
从 Powershell 中的列表中选择交互式
原标题:Interactive Select from List in Powershell

是否有一个插件或工具可以让我向用户显示一个对象列表( Format- Table 样式), 并允许用户使用光标从列表中选择一个选项, 包括可能滚动一个长列表 。 我希望能够做这样的事情 :

Get- User - anr $search /code% group%code > Get- Choice

此脚本应该在控制台提示处显示匹配账户列表, 允许用户交互滚动列表上下滚动, 并通过按 Enter (或用户点击逃跑时通过无效) 选择一个选项。 只有一个账户会被传递给 Set- User, 而不是所有匹配选项列表 。

显然,细节可能有所不同。 虽然我更喜欢一个控制台版本, 但图形版本可以被接受( 显示一个 Windows 对话框 ) 。 确切的按键可能不同 。 但核心目标( 接受列表、 获取用户输入、 退出结果) 应该实现 。

最佳回答

在 <% 1 > 中 <% 1 > :

Get-User -anr $search | Out-GridView -PassThru | Set-User -EnableAccount true
问题回答

查看 < a href=> "http://poshcode.org/2628" rel = "no follow" > out-form

伪用 :

out-form -title "Enable Account" -data (Get-user -anr $search) -columnNames ("AccountName") `
    -columnProperties ("SamAccountName") -actions @{Enable It!" = { $_ | Set-User -EnableAccount true}}




相关问题
Mutually exclusive powershell parameters

SCENARIO I m writing a cmdlet for Powershell 2.0 using Visual Studio 2008 and .NET 3.5 the cmdlet requires 3 arguments. my intended grammar of the cmdlet is something like this: cmdletname [foo|...

Run a program from PowerShell with timeout

I ll write a script that runs a program and wait for it finished. But if the program is not finished within a specified time I want that the program is killed.

How to transpose data in powershell

I have a file that looks like this: a,1 b,2 c,3 a,4 b,5 c,6 (...repeat 1,000s of lines) How can I transpose it into this? a,b,c 1,2,3 4,5,6 Thanks

Powershell v2 remoting and delegation

I have installed Powershell V2 on 2 machines and run Enable-PsRemoting on both of them. Both machines are Win 2003 R2 and are joined to the same active directory domain and I can successfully run ...

PowerShell -match operator and multiple groups

I have the following log entry that I am processing in PowerShell I m trying to extract all the activity names and durations using the -match operator but I am only getting one match group back. I m ...