Get-Mailbox.Psm1
|
#Function 1
Function New-TeamsusingCSV { <# .SYNOPSIS Create Teams using CSV file. .DESCRIPTION Using this script you can create Mirosoft Teams using csv file and this function using MicrosoftTeams Module. .EXAMPLE New-TeamsusingCSV -Path "C:\temp\TeamsDetails.CSV" Create Teams using CSV file. #> [CmdletBinding()] param( [Parameter(Mandatory=$true)] [string] # Give the CSV Path of the New Teams details. $Path ) function Create-Channel { param ( $ChannelName,$GroupId ) Process { try { $teamchannels = $ChannelName -split ";" if($teamchannels) { for($i =0; $i -le ($teamchannels.count - 1) ; $i++) { New-TeamChannel -GroupId $GroupId -DisplayName $teamchannels[$i] } } } Catch { } } } function Add-Users { param( $Users,$GroupId,$CurrentUsername,$Role ) Process { try{ $teamusers = $Users -split ";" if($teamusers) { for($j =0; $j -le ($teamusers.count - 1) ; $j++) { if($teamusers[$j] -ne $CurrentUsername) { Add-TeamUser -GroupId $GroupId -User $teamusers[$j] -Role $Role } } } } Catch { } } } function Create-NewTeam { param ( $ImportPath ) Process { Import-Module MicrosoftTeams $cred = Get-Credential $username = $cred.UserName Connect-MicrosoftTeams -Credential $cred $teams = Import-Csv -Path $ImportPath foreach($team in $teams) { $getteam= get-team |where-object { $_.displayname -eq $team.TeamsName} If($getteam -eq $null) { Write-Host "Start creating the team: " $team.TeamsName $group = New-Team -alias $team.TeamsName -displayname $team.TeamsName -AccessType $team.TeamType Write-Host "Creating channels..." Create-Channel -ChannelName $team.ChannelName -GroupId $group.GroupId Write-Host "Adding team members..." Add-Users -Users $team.Members -GroupId $group.GroupId -CurrentUsername $username -Role Member Write-Host "Adding team owners..." Add-Users -Users $team.Owners -GroupId $group.GroupId -CurrentUsername $username -Role Owner Write-Host "Completed creating the team: " $team.TeamsName $team=$null } } } } Create-NewTeam -ImportPath $Path } #function 2 Function Export-ArchivedTeams { <# .SYNOPSIS Export Archived Teams as CSV file. .DESCRIPTION Using this script you can Export archived Mirosoft Teams as csv file and this function using SharePointPnPPowerShellOnline Module. .EXAMPLE Export-ArchivedTeams -ExportPath "C:\temp\ArchivedTeamsDetails.CSV" Export Archived Teams as CSV file. #> [CmdletBinding()] param( [Parameter(Mandatory=$true)] [string] # Give the CSV path for export Archived Teams details. $ExportPath ) process{ Connect-PnPOnline -Scopes "Group.Read.All","Group.ReadWrite.All" $accesstoken =Get-PnPAccessToken $group = Invoke-RestMethod -Headers @{Authorization = "Bearer $accesstoken"} -Uri "https://graph.microsoft.com/beta/groups?`$filter=resourceProvisioningOptions/any(c:c+eq+`'Team`')" -Method Get $TeamsList = @() $i=1 do { foreach($value in $group.value) { Write-Progress -Activity "Get All Groups" -status "Found Group $i" -percentComplete ($i / $group.value.count*100) $id= $value.id Try { $team = Invoke-RestMethod -Headers @{Authorization = "Bearer $accesstoken"} -Uri https://graph.microsoft.com/beta/teams/$id -Method Get if($team -ne $null -and $team.isArchived -eq $true) { $Teams = "" | Select "TeamsName","TeamType" $Teams.TeamsName = $value.displayname $Teams.TeamType = $value.visibility $TeamsList+= $Teams $Teams=$null } } Catch { $team = $null } $i++ } if ($group.'@odata.nextLink' -eq $null ) { break } else { $group = Invoke-RestMethod -Headers @{Authorization = "Bearer $accesstoken"} -Uri $group.'@odata.nextLink' -Method Get } }while($true); $TeamsList $TeamsList |Export-csv $ExportPath -NoTypeInformation } } #Function 3 function Export-TeamsList { <# .SYNOPSIS Export Microsoft Teams as CSV file. .DESCRIPTION Using this script you can Export Mirosoft Teams as csv file and this function using SharePointPnPPowerShellOnline Module. .EXAMPLE Export-TeamsList -ExportPath "C:\temp\ArchivedTeamsDetails.CSV" Export Microsoft Teams as CSV file. #> [CmdletBinding()] param( [Parameter(Mandatory=$true)] [string] # Give the CSV path for export Teams details. $ExportPath ) process{ Connect-PnPOnline -Scopes "Group.Read.All","User.ReadBasic.All" $accesstoken =Get-PnPAccessToken $MTeams = Invoke-RestMethod -Headers @{Authorization = "Bearer $accesstoken"} -Uri "https://graph.microsoft.com/beta/groups?`$filter=resourceProvisioningOptions/any(c:c+eq+`'Team`')" -Method Get $TeamsList = @() $i=1 do { foreach($value in $MTeams.value) { Write-Progress -Activity "Get All Teams" -status "Found Team $i" -percentComplete ($i / $MTeams.value.count*100) $id= $value.id Try { $team = Invoke-RestMethod -Headers @{Authorization = "Bearer $accesstoken"} -Uri https://graph.microsoft.com/beta/Groups/$id/channels -Method Get } Catch { } $Owner = Invoke-RestMethod -Headers @{Authorization = "Bearer $accesstoken"} -Uri https://graph.microsoft.com/v1.0/Groups/$id/owners -Method Get $Members = Invoke-RestMethod -Headers @{Authorization = "Bearer $accesstoken"} -Uri https://graph.microsoft.com/v1.0/Groups/$id/Members -Method Get $Teams = "" | Select "TeamsName","TeamType","Channelcount","ChannelName","Owners","MembersCount","Members" $Teams.TeamsName = $value.displayname $Teams.TeamType = $value.visibility $Teams.ChannelCount = $team.value.id.count $Teams.ChannelName = $team.value.displayName -join ";" $Teams.Owners = $Owner.value.userPrincipalName -join ";" $Teams.MembersCount = $Members.value.userPrincipalName.count $Teams.Members = $Members.value.userPrincipalName -join ";" $TeamsList+= $Teams $teamaccesstype=$null $errorMessage =$null $Teams=$null $team =$null $i++ } if ($group.'@odata.nextLink' -eq $null ) { break } else { $group = Invoke-RestMethod -Headers @{Authorization = "Bearer $accesstoken"} -Uri $group.'@odata.nextLink' -Method Get } }while($true); $TeamsList $TeamsList | Export-csv $ExportPath -NoTypeInformation } } |