In case of throttling ot large volume of request processing, there might be time out issues, throttling issues, etc.. skipping the setting application
$clientId = "xxxxxx" #Read-Host "Please enter the Entra Id registration:"
# Connection String Variables, including client specific ID and Tenant
$TenantUrl = "https://contoso.sharepoint.com"
$TenantName = "contoso"
function Invoke-With-Retry {
param (
[scriptblock]$Operation,
[string]$ErrorMessage,
[string]$SuccessMessage,
[int]$MaxRetries = 5,
[int]$RetryDelay = 5
)
$attempt = 0
while ($attempt -lt $MaxRetries) {
try {
& $Operation
Log-Message $SuccessMessage "Success"
return
}
catch {
$attempt++
if ($attempt -ge $MaxRetries) {
Log-Message "$ErrorMessage. $_" "Error"
} else {
Start-Sleep -Seconds $RetryDelay
}
}
}
}
function Apply-Teams-Settings {
param (
[string]$teamName,
[string]$displayName
)
try {
Log-Message "Setting up Teams settings started for teams:$($teamName)." "Info"
Start-Sleep -Seconds 20
# Update Team display name
Invoke-With-Retry -Operation {
Set-PnPTeamsTeam -Identity $teamName -DisplayName $displayName
} -ErrorMessage "Failed to update display name for :$($teamName)" -SuccessMessage "Successfully updated team display name:$($teamName)."
# Set allow to create and update channels
Invoke-With-Retry -Operation {
Set-PnPTeamsTeam -Identity $teamName -AllowCreateUpdateChannels $false
} -ErrorMessage "Failed to disable allow create and update channels on teams:$($teamName)" -SuccessMessage "Successfully disabled allow create and update channels on teams:$($teamName)."
# Set allow to delete channels
Invoke-With-Retry -Operation {
Set-PnPTeamsTeam -Identity $teamName -AllowDeleteChannels $false
} -ErrorMessage "Failed to disable allow to delete channel on teams:$($teamName)" -SuccessMessage "Successfully disabled allow to delete channel on teams:$($teamName)."
# Set allow to add and remove apps
Invoke-With-Retry -Operation {
Set-PnPTeamsTeam -Identity $teamName -AllowAddRemoveApps $false
} -ErrorMessage "Failed to disable allow to add and remove app on teams:$($teamName)" -SuccessMessage "Successfully disabled allow to add and remove app on teams:$($teamName)."
# Set allow to add and remove tabs
Invoke-With-Retry -Operation {
Set-PnPTeamsTeam -Identity $teamName -AllowCreateUpdateRemoveTabs $false
} -ErrorMessage "Failed to disable allow to add and remove tabs on teams:$($teamName)" -SuccessMessage "Successfully disabled allow to add and remove tabs on teams:$($teamName)."
# Set allow to create, update, and remove connectors
Invoke-With-Retry -Operation {
Set-PnPTeamsTeam -Identity $teamName -AllowCreateUpdateRemoveConnectors $false
} -ErrorMessage "Failed to disable allow to create, update, and remove connectors on teams:$($teamName)" -SuccessMessage "Successfully disabled allow to create, update, and remove connectors on teams:$($teamName)."
# Set disable custom memes
Invoke-With-Retry -Operation {
Set-PnPTeamsTeam -Identity $teamName -AllowCustomMemes $false
} -ErrorMessage "Failed to disable custom memes on teams:$($teamName)" -SuccessMessage "Successfully disabled custom memes on teams:$($teamName)."
# Remove Notes tab
Invoke-With-Retry -Operation {
Remove-PnPTeamsTab -Team $teamName -Channel "General" -Identity "Notes" -Force
} -ErrorMessage "Failed to remove Notes tab on teams:$($teamName)" -SuccessMessage "Successfully removed Notes tab on teams:$($teamName)."
Log-Message "Setting up teams setting is finished for teams:$($teamName)." "Success"
}
catch {
Log-Message "Failed to apply Teams settings for teams:$($teamName). $_" "Error"
}
}
connect-pnponline -clientId "xxxx" -Url "https://contoso-admin.sharepoint.com"
Apply-Teams-Settings -teamName "TeamName" -displayName "Team Name"