简体   繁体   English

如何将参数沿管道传递给不接受管道输入的 function?

[英]How do I pass a parameter down the pipeline to a function that doesn't accept pipeline input?

I've got a text file that contains a list of user identities.我有一个包含用户身份列表的文本文件。 I want to pass each member on that list to Get-csMeetingMigrationStatus and get back UserPrincipalName, Status and LastMessage.我想将该列表中的每个成员传递给 Get-csMeetingMigrationStatus 并取回 UserPrincipalName、Status 和 LastMessage。 From there I want to output to gridview as an eyes on test for migration status.从那里我想 output 到 gridview 作为迁移状态测试的眼睛。

I'd like to do this in one pipeline but can't work it out.我想在一个管道中执行此操作,但无法解决。 I know that Get-csMeetingMigrationStatus does not take pipeline input for its parameter -identity so I have to use another means of passing that parameter to the function.我知道 Get-csMeetingMigrationStatus 不为其参数-identity 接受管道输入,因此我必须使用另一种方法将该参数传递给 function。 I've done things like this before and am wondering if the fact that the list of users is an import from a text file rather than an array created from scratch is the cause.我以前做过这样的事情,我想知道用户列表是从文本文件导入而不是从头开始创建的数组这一事实是否是原因。

I needed to get this working asap so thought I'd just put it all in a foreach loop as below.我需要尽快让这个工作,所以我想我只是把它放在一个 foreach 循环中,如下所示。 I know the example below doesn't give me all I want regards output but even the sample below fails.我知道下面的例子并没有给我所有我想要的关于 output 但即使下面的示例也失败了。

$UserDetails = Get-Content -path c:\test.txt
foreach ($ud in $UserDetails) {
        Get-csMeetingMigrationStatus -identity $ud | Select-Object Userprincipalname, status, lastmessage
}

When I run the above the return for the first identity is the property headers for my connect-microsoftteams connection.当我运行上面的第一个标识时,返回的是我的 connect-microsoftteams 连接的属性标头。 Subsequent iterations return a blank line.随后的迭代返回一个空行。 For each iteration of the foreach loop, if I copy and paste the command in the foreach statement into the terminal window and run it, the correct information for each user is displayed.对于 foreach 循环的每次迭代,如果我将 foreach 语句中的命令复制并粘贴到终端 window 并运行它,则会显示每个用户的正确信息。 I don't understand how that can be.我不明白这怎么可能。

Ultimately I'd like to push all this down a single pipeline and output to gridview.最终,我想将所有这些都推到一条管道中,并将 output 推到 gridview。

If anyone can assist with either problem above I'd appreciate it as I've tried sorting this for a good number of hours now and can't find a solution.如果有人可以帮助解决上述任一问题,我将不胜感激,因为我已经尝试对这个问题进行了好几个小时的排序,但找不到解决方案。

Thanks谢谢

Use the ForEach-Object cmdlet :使用ForEach-Object cmdlet

Get-Content -path c:\test.txt |ForEach-Object {
    Get-CsMeetingMigrationStatus -identity $_ | Select-Object Userprincipalname, status, lastmessage
} |Out-GridView

Nesting the pipeline inside ForEach-Object means that we can supply another downstream cmdlet (in this case Out-GridView ) with whatever output is produced by it (unlike with the foreach(){} loop statement)将管道嵌套在ForEach-Object中意味着我们可以为另一个下游 cmdlet(在本例中Out-GridView )提供由它生成的任何 output (与foreach(){}循环语句不同)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 Powershell 管道 output 放入不支持管道输入(多个参数)的命令中? - How can I put Powershell pipeline output into a command that doesn't support pipeline input (multiple arguments)? Mock 函数应该如何接受 Pester 中的管道输入? - How should a Mock function accept pipeline input in Pester? 如何让 WSL Vim 接受来自 Powershell 的管道输入? - How do I get WSL Vim to accept pipeline input from Powershell? 如何将foreach-object输出传递给接受管道输入的函数? - How to pass foreach-object output to a function accepting pipeline input? 我如何有一个从 args 或 Powershell 管道中获取输入的数组参数? - How do I have an array parameter that takes input from the args or the pipeline in Powershell? PowerShell:如何将对象传递给接受输入“ByPropertyName”的参数? - PowerShell: How can I pipeline objects to a parameter that accepts input “ByPropertyName”? 在Powershell函数中处理管道和参数输入 - Handling pipeline and parameter input in a Powershell function 如何将参数传递给jenkins管道中的powershell脚本 - How to pass a parameter to a powershell script in a jenkins pipeline 在Powershell高级功能中,如何检测BEGIN块中的管道输入? - In a Powershell advanced function, how do I detect pipeline input in my BEGIN block? 如何编写接受管道输入的PowerShell脚本? - How do I write a PowerShell script that accepts pipeline input?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM