powershellmicrosoft-teamsskype-for-business

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. From there I want to output to gridview as an eyes on test for migration status.

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. 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. I know the example below doesn't give me all I want regards output but even the sample below fails.

$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. 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. I don't understand how that can be.

Ultimately I'd like to push all this down a single pipeline and output to 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


Solution

  • Use the 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)