Tag: pscmdlet

PSCmdlet动态自动完成一个参数(如Get-Process)

在powershell中,某些参数具有动态自动完成行为。 例如,Get-Process参数Name。 我可以使用TAB迭代我的所有进程。 我想在我的PSCmdlet中使用此行为。 但问题是,我只知道如何使用静态自动完成值来做到这一点。 看例子: public class TableDynamicParameters { [Parameter] [ValidateSet(“Table1”, “Table2”)] public string[] Tables { get; set; } } 这是一个如何使用原生powershell http://blogs.technet.com/b/heyscriptingguy/archive/2014/03/21/use-dynamic-parameters-to-populate-list-of-printer-names完成此操作的示例。 ASPX 它适用于@bouvierr public string[] Tables { get; set; } public object GetDynamicParameters() { if (!File.Exists(Path)) return null; var tableNames = new List(); if (TablesCache.ContainsKey(Path)) { tableNames = TablesCache[Path]; } else { try […]