Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试创建一个调用 Powershell 函数的 cmdlet。这可以做到吗?
想法是让静态 cmdlet 枚举一组数据,然后调用定义的函数为每个项目做一些事情。我总是可以复制-粘贴枚举部分的基本模板,但是在修改参数等时很容易出错。
当然,在 PSCmdlet 上使用 InvokeCommand 属性(假设您从这个基类派生),例如:
Collection<PSObject> result = this.InvokeCommand.InvokeScript("somefunc", true, PipelineResultTypes.None, null, new[] {1,2,3});
请注意,在这种情况下somefunc,需要三个参数(1,2,3)并且没有管道输入(传递null给第四个参数)。
somefunc
null