diff --git a/scripts/teams-export-details-using-teams-cli/README.md b/scripts/teams-export-details-using-teams-cli/README.md new file mode 100644 index 000000000..c4a087c2c --- /dev/null +++ b/scripts/teams-export-details-using-teams-cli/README.md @@ -0,0 +1,105 @@ +--- +plugin: add-to-gallery +--- + +# Fetch Teams Information Using Teams PowerShell And Export To CSV + +## Summary + +This script showcases the use of Microsoft Teams PowerShell commands to retrieve team details, including ID, name, owner, members, channels, etc., and then exports the information to a CSV file. + +![Example Screenshot](assets/example.png) + +## Implementation + +Open Windows Powershell ISE +Create a new file and write a script +Install the Microsoft Teams module if it is not already installed using the `Install-Module MicrosoftTeams` command. + +Now we will see all the steps which we required to achieve the solution: + +1. Begin by establishing a connection to Microsoft Teams. +2. Retrieve the necessary details and store them in an array. +3. Export the collected data to a CSV file. + +So at the end, our script will be like this, + +# [MicrosoftTeams PowerShell](#tab/teamsps) + +```powershell + +$userName = "chandani@domain.onmicrosoft.com" +$password = "********" +$secureStringPwd = $password | ConvertTo-SecureString -AsPlainText -Force +$creds = New-Object System.Management.Automation.PSCredential -ArgumentList $userName, $secureStringPwd +$dateTime = "_{0:MM_dd_yy}_{0:HH_mm_ss}" -f (Get-Date) +$basePath = "D:\Contributions\Scripts\Logs\" +$csvPath = $basePath + "\TeamsData" + $dateTime + ".csv" +$global:teamData = @() + +Function Login() { + [cmdletbinding()] + param([parameter(Mandatory = $true, ValueFromPipeline = $true)] $creds) + + #connect to teams + Write-Host "Connecting to Teams..." -f Yellow + Connect-MicrosoftTeams -Credential $creds + Write-Host "Connection successfully!..." -f Green +} + +Function GetTeamsInformation { + try { + Write-Host "Getting teams details..." -ForegroundColor Yellow + $allTeams = Get-Team + + Foreach ($team in $allTeams) + { + #Collect Team Data + $teamGroupId = $team.GroupId.ToString() + $teamChannels = Get-TeamChannel -GroupId $teamGroupId | Select-Object -Property DisplayName + $teamChannelsName = $teamChannels | Foreach {"$($_.DisplayName)"} + $joinedTeamChannels = [String]::Join('; ',$teamChannelsName) + + $global:teamData += [PSCustomObject] @{ + TeamName = $team.DisplayName + TeamID = $teamGroupId + MailAlias = $team.MailNickName + TeamType = $team.Visibility + TeamDescription = $team.Description + TeamChannels = $joinedTeamChannels + TeamOwners = (Get-TeamUser -GroupId $teamGroupId | Where {$_.Role -eq 'Owner'}).Name -join '; ' + TeamMembers = (Get-TeamUser -GroupId $teamGroupId | Where {$_.Role -eq 'Member'}).Name -join '; ' + } + } + Write-Host "Getting teams details successfully!..." -ForegroundColor Green + } + catch { + Write-Host "Error in getting teams information:" $_.Exception.Message -ForegroundColor Red + } + + Write-Host "Exporting to CSV..." -ForegroundColor Yellow + $global:teamData | Export-Csv $csvPath -NoTypeInformation -Append + Write-Host "Exported to CSV successfully!..." -ForegroundColor Gree +} + +Function StartProcessing { + Login($creds); + GetTeamsInformation +} + +StartProcessing + +``` + +[!INCLUDE [More about Microsoft Teams PowerShell](../../docfx/includes/MORE-TEAMSPS.md)] + +*** + +## Contributors + +| Author(s) | +|-----------| +| Chandani Prajapati (https://github.com/chandaniprajapati) | + +[!INCLUDE [DISCLAIMER](../../docfx/includes/DISCLAIMER.md)] + diff --git a/scripts/teams-export-details-using-teams-cli/assets/example.png b/scripts/teams-export-details-using-teams-cli/assets/example.png new file mode 100644 index 000000000..644d99a6a Binary files /dev/null and b/scripts/teams-export-details-using-teams-cli/assets/example.png differ diff --git a/scripts/teams-export-details-using-teams-cli/assets/preview.png b/scripts/teams-export-details-using-teams-cli/assets/preview.png new file mode 100644 index 000000000..8923005d6 Binary files /dev/null and b/scripts/teams-export-details-using-teams-cli/assets/preview.png differ diff --git a/scripts/teams-export-details-using-teams-cli/assets/sample.json b/scripts/teams-export-details-using-teams-cli/assets/sample.json new file mode 100644 index 000000000..05180c7bb --- /dev/null +++ b/scripts/teams-export-details-using-teams-cli/assets/sample.json @@ -0,0 +1,52 @@ +[ + { + "name": "teams-export-details-using-teams-cli", + "source": "pnp", + "title": "Fetch Microsoft Teams Details And Export To CSV", + "shortDescription": "Retrieve team information such as team name, ID, owner, channels, etc., and export it to CSV using Microsoft Teams PowerShell.", + "url": "https://pnp.github.io/script-samples/teams-export-details-using-teams-cli/README.html", + "longDescription": [ + "" + ], + "creationDateTime": "2023-11-16", + "updateDateTime": "2023-11-16", + "products": [ + "Teams" + ], + "metadata": [ + { + "key": "MICROSOFTTEAMS-POWERSHELL", + "value": "3.0.0" + } + ], + "categories": [ + "Report", + "Connect-MicrosoftTeams", + "Get-Team", + "Get-TeamUser", + "Get-TeamChannel" + ], + "thumbnails": [ + { + "type": "image", + "order": 100, + "url": "https://raw.githubusercontent.com/pnp/script-samples/main/scripts/teams-export-details-using-teams-cli/assets/preview.png", + "alt": "" + } + ], + "authors": [ + { + "gitHubAccount": "chandaniprajapati", + "pictureUrl": "https://avatars.githubusercontent.com/u/52065929?v=4", + "name": "Chandani Prajapati" + } + ], + "references": [ + { + "name": "Want to learn more about Microsoft Teams PowerShell and the cmdlets", + "description": "Check out the Microsoft Teams PowerShell documentation site to get started and for the reference to the cmdlets.", + "url": "https://docs.microsoft.com/en-us/microsoftteams/teams-powershell-overview" + } + ] + } +] \ No newline at end of file