-1

I wanna export to csv file like this format.

Team name | User name | Role
================================

But, Get-Teamuser cmdlet result is

Userid | User | Name | Role
===============================

What should I do?

TheGameiswar
  • 27,855
  • 8
  • 56
  • 94
ciscons
  • 1
  • 1
  • 5

2 Answers2

1

You can use calculated expressions like below

get-teamuser |select @{
 Name = 'Team name';  Expression = {$_.name}},@{ Name = 'user name';  Expression = {$_.user +' '+$_.name}},role| export-csv -path c:\teamsdata.csv
TheGameiswar
  • 27,855
  • 8
  • 56
  • 94
  • Thank you for your response. But I have one more team, and I want to get the following results. https://i.stack.imgur.com/8OI0q.png – ciscons Feb 05 '20 at 04:04
0

The script will be as follows:

Connect-MicrosoftTeams

$output=@()
$teams = Import-Csv "C:\Get-Team Wise user details\Teams.csv" 

ForEach ($team in $teams) {
    $teamUsers = Get-TeamUser -GroupId $team.GroupId 

    ForEach ($teamUser in $teamUsers) {
        $userObj = New-Object PSObject 

        $userObj | Add-Member NoteProperty -Name "Team Display Name" -Value $team.DisplayName
        $userObj | Add-Member NoteProperty -Name "User Name" -Value $teamUser.Name
        $userObj | Add-Member NoteProperty -Name "User SMTP Address" -Value $teamUser.User
        $userObj | Add-Member NoteProperty -Name "User Role" -Value $teamUser.Role

        $output += $userObj
        Write-Output "$($team.DisplayName);$($teamUser.Name);$($teamUser.User);$($teamUser.Role)"
    }
}

$output | Export-csv -Path C:\BatchWiseUserDetails.csv -NoTypeInformation -Encoding UTF8

The import CSV need to have only one column called "GroupID"

fcdt
  • 2,371
  • 5
  • 14
  • 26
Akash Saha
  • 21
  • 2