[英]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.