Skip to content

Commit

Permalink
ConfigureTeamsThirdPartyFiles
Browse files Browse the repository at this point in the history
  • Loading branch information
OfficialEsco committed Apr 20, 2024
1 parent 4d3ace5 commit f9e1151
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
42 changes: 42 additions & 0 deletions Modules/CIPPCore/Public/GraphHelper/New-TeamsAPIPOSTRequest.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
function New-TeamsAPIPOSTRequest {
<#
.FUNCTIONALITY
Internal
#>
Param(
$uri,
$tenantid,
$body,
$method = 'PUT',
$Resource = '48ac35b8-9aa8-4d74-927d-1f4a14a0b239'
)

if ((Get-AuthorisedRequest -Uri $uri -TenantID $tenantid)) {
$token = Get-ClassicAPIToken -Tenant $tenantid -Resource $Resource

$headers = @{
Authorization = "Bearer $($token.access_token)"
'x-ms-client-request-id' = [guid]::NewGuid().ToString()
'x-ms-client-session-id' = [guid]::NewGuid().ToString()
'x-ms-correlation-id' = [guid]::NewGuid()
'X-Requested-With' = 'XMLHttpRequest'
'x-ms-tnm-applicationid' = '045268c0-445e-4ac1-9157-d58f67b167d9'
}

try {
$Data = Invoke-RestMethod -Uri $uri -Method $method -Body $body -ContentType 'application/json; charset=utf-8' -Headers $headers
} catch [System.Net.WebException] {
Write-LogMessage -API 'Standards' -Tenant $tenant -message "Teams API Post Request failed. Error: $($_.exception.message)" -sev Error

$Message = if ($_.ErrorDetails.Message) {
Get-NormalizedError -Message $_.ErrorDetails.Message
} else {
$_.Exception.message
}
throw $Message
}
return $Data
} else {
Write-Error 'Not allowed. You cannot manage your own tenant or tenants not under your scope'
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
function Invoke-CIPPStandardConfigureTeamsThirdPartyFiles {
<#
.FUNCTIONALITY
Internal
#>

param($Tenant, $Settings)
$CurrentSetting = New-TeamsAPIGetRequest -Uri "https://api.interfaces.records.teams.microsoft.com/Skype.Policy/Tenants/$($Tenant)/configurations/TeamsClientConfiguration/configuration/Global" -tenantid $tenant |
Select-Object AllowShareFile, AllowDropBox, AllowBox, AllowGoogleDrive, AllowEgnyte

$StateIsCorrect = $CurrentSetting.AllowShareFile -eq $Settings.AllowShareFile -and
$CurrentSetting.AllowDropBox -eq $Settings.AllowDropBox -and
$CurrentSetting.AllowBox -eq $Settings.AllowBox -and
$CurrentSetting.AllowGoogleDrive -eq $Settings.AllowGoogleDrive -and
$CurrentSetting.AllowEgnyte -eq $Settings.AllowEgnyte

if ($Settings.remediate) {
if ($StateIsCorrect) {
Write-LogMessage -API 'Standards' -Tenant $tenant -message 'Microsoft Teams Third Party Files are already configured.' -sev Info
} else {
Write-LogMessage -API 'Standards' -Tenant $tenant -message 'Remediating Microsoft Teams Third Party Files.' -sev Info
$body = @{
"AllowShareFile" = $Settings.AllowShareFile
"AllowDropBox" = $Settings.AllowDropBox
"AllowBox" = $Settings.AllowBox
"AllowGoogleDrive" = $Settings.AllowGoogleDrive
"AllowEgnyte" = $Settings.AllowEgnyte
}

try {
$params = @{
Uri = "https://api.interfaces.records.teams.microsoft.com/Skype.Policy/Tenants/$($Tenant)/configurations/TeamsClientConfiguration/configuration/Global"
TenantId = $tenant
Body = $body
}
New-TeamsAPIPOSTRequest @params
} catch {
Write-LogMessage -API 'Standards' -Tenant $tenant -message "Failed to set Microsoft Teams Third Party Files settings. Error: $($_.exception.message)" -sev Error
}
}
}

if ($Settings.alert) {
if ($StateIsCorrect) {
Write-LogMessage -API 'Standards' -Tenant $tenant -message 'Microsoft Teams Third Party Files are configured.' -sev Info
} else {
Write-LogMessage -API 'Standards' -Tenant $tenant -message 'Microsoft Teams Third Party Files are not configured.' -sev Alert
}
}

if ($Settings.report) {
Add-CIPPBPAField -FieldName 'TeamsThirdPartyFiles' -FieldValue [bool]$StateIsCorrect -StoreAs bool -Tenant $tenant
}
}

0 comments on commit f9e1151

Please sign in to comment.