Skip to content

Commit

Permalink
Merge pull request #54 from KelvinTegelaar/dev
Browse files Browse the repository at this point in the history
[pull] dev from KelvinTegelaar:dev
  • Loading branch information
kris6673 authored Jun 3, 2024
2 parents 43623ca + 8fc3534 commit 0bfa56b
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 37 deletions.
27 changes: 12 additions & 15 deletions Modules/CIPPCore/Public/Alerts/Get-CIPPAlertAppSecretExpiry.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,20 @@ function Get-CIPPAlertAppSecretExpiry {
try {
Write-Host "Checking app expire for $($TenantFilter)"
$appList = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/applications?`$select=appId,displayName,passwordCredentials" -tenantid $TenantFilter
$AlertData = foreach ($App in $applist) {
Write-Host "checking $($App.displayName)"
if ($App.passwordCredentials) {
foreach ($Credential in $App.passwordCredentials) {
if ($Credential.endDateTime -lt (Get-Date).AddDays(30) -and $Credential.endDateTime -gt (Get-Date).AddDays(-7)) {
Write-Host ("Application '{0}' has secrets expiring on {1}" -f $App.displayName, $Credential.endDateTime)
@{ DisplayName = $App.displayName; Expires = $Credential.endDateTime }
}
} catch {
return
}

$AlertData = foreach ($App in $applist) {
Write-Host "checking $($App.displayName)"
if ($App.passwordCredentials) {
foreach ($Credential in $App.passwordCredentials) {
if ($Credential.endDateTime -lt (Get-Date).AddDays(30) -and $Credential.endDateTime -gt (Get-Date).AddDays(-7)) {
Write-Host ("Application '{0}' has secrets expiring on {1}" -f $App.displayName, $Credential.endDateTime)
@{ DisplayName = $App.displayName; Expires = $Credential.endDateTime }
}
}
Write-AlertTrace -cmdletName $MyInvocation.MyCommand -tenantFilter $TenantFilter -data $AlertData

} else {
Write-Host "Skipping app expire for $($TenantFilter)"
}
} catch {
#Write-AlertMessage -tenant $($TenantFilter) -message "Failed to check App registration expiry for $($TenantFilter): $(Get-NormalizedError -message $_.Exception.message)"
}
Write-AlertTrace -cmdletName $MyInvocation.MyCommand -tenantFilter $TenantFilter -data $AlertData
}

24 changes: 13 additions & 11 deletions Modules/CIPPCore/Public/Alerts/Get-CIPPAlertQuotaUsed.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@ function Get-CIPPAlertQuotaUsed {
$TenantFilter
)


try {
$AlertData = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/reports/getMailboxUsageDetail(period='D7')?`$format=application/json" -tenantid $TenantFilter | ForEach-Object {
if ($_.StorageUsedInBytes -eq 0) { return }
$PercentLeft = [math]::round(($_.storageUsedInBytes / $_.prohibitSendReceiveQuotaInBytes) * 100)
if ($InputValue) { $Value = [int]$InputValue } else { $Value = 90 }
if ($PercentLeft -gt $Value) {
"$($_.userPrincipalName): Mailbox is more than $($value)% full. Mailbox is $PercentLeft% full"
}

}
Write-AlertTrace -cmdletName $MyInvocation.MyCommand -tenantFilter $TenantFilter -data $AlertData
$AlertData = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/reports/getMailboxUsageDetail(period='D7')?`$format=application/json" -tenantid $TenantFilter
} catch {
return
}
$AlertData | ForEach-Object {
if ($_.StorageUsedInBytes -eq 0) { return }
$PercentLeft = [math]::round(($_.storageUsedInBytes / $_.prohibitSendReceiveQuotaInBytes) * 100)
if ($InputValue) { $Value = [int]$InputValue } else { $Value = 90 }
if ($PercentLeft -gt $Value) {
"$($_.userPrincipalName): Mailbox is more than $($value)% full. Mailbox is $PercentLeft% full"
}

}
Write-AlertTrace -cmdletName $MyInvocation.MyCommand -tenantFilter $TenantFilter -data $AlertData

}
19 changes: 9 additions & 10 deletions Modules/CIPPCore/Public/Alerts/Get-CIPPAlertSharepointQuota.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@ function Get-CIPPAlertSharepointQuota {
$sharepointToken = (Get-GraphToken -scope "https://$($tenantName)-admin.sharepoint.com/.default" -tenantid $TenantFilter)
$sharepointToken.Add('accept', 'application/json')
$sharepointQuota = (Invoke-RestMethod -Method 'GET' -Headers $sharepointToken -Uri "https://$($tenantName)-admin.sharepoint.com/_api/StorageQuotas()?api-version=1.3.2" -ErrorAction Stop).value
if ($sharepointQuota) {
if ($InputValue -Is [Boolean]) { $Value = 90 } else { $Value = $InputValue }
$UsedStoragePercentage = [int](($sharepointQuota.GeoUsedStorageMB / $sharepointQuota.TenantStorageMB) * 100)
if ($UsedStoragePercentage -gt $Value) {
$AlertData = "SharePoint Storage is at $($UsedStoragePercentage)%. Your alert threshold is $($Value)%"
Write-AlertTrace -cmdletName $MyInvocation.MyCommand -tenantFilter $TenantFilter -data $AlertData
}
}
} catch {
return
}
if ($sharepointQuota) {
if ($InputValue -Is [Boolean]) { $Value = 90 } else { $Value = $InputValue }
$UsedStoragePercentage = [int](($sharepointQuota.GeoUsedStorageMB / $sharepointQuota.TenantStorageMB) * 100)
if ($UsedStoragePercentage -gt $Value) {
$AlertData = "SharePoint Storage is at $($UsedStoragePercentage)%. Your alert threshold is $($Value)%"
Write-AlertTrace -cmdletName $MyInvocation.MyCommand -tenantFilter $TenantFilter -data $AlertData
}
}


}
48 changes: 48 additions & 0 deletions Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardBookings.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
function Invoke-CIPPStandardBookings {
<#
.FUNCTIONALITY
Internal
#>
param($Tenant, $Settings)

# Input validation
if ([string]::isNullOrEmpty($Settings.state) -or $Settings.state -eq 'Select a value') {
Write-LogMessage -API 'Standards' -tenant $tenant -message 'BookingsEnabled: Invalid state parameter set' -sev Error
Exit
}

$CurrentState = (New-ExoRequest -tenantid $Tenant -cmdlet 'Get-OrganizationConfig').BookingsEnabled
$WantedState = if ($Settings.state -eq 'true') { $true } else { $false }
$StateIsCorrect = if ($CurrentState -eq $WantedState) { $true } else { $false }

if ($Settings.remediate -eq $true) {
Write-Host 'Time to remediate'
if ($StateIsCorrect -eq $false) {
try {
New-ExoRequest -tenantid $Tenant -cmdlet 'Set-OrganizationConfig' -cmdParams @{ BookingsEnabled = $WantedState } -useSystemMailbox $true
Write-LogMessage -API 'Standards' -tenant $tenant -message "Successfully set the tenant Bookings state to $($Settings.state)" -sev Info
} catch {
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to set the tenant Bookings state to $($Settings.state). Error: $ErrorMessage" -sev Error
}
} else {
Write-LogMessage -API 'Standards' -tenant $tenant -message "The tenant Bookings state is already set correctly to $($Settings.state)" -sev Info
}

}

if ($Settings.alert -eq $true) {
if ($StateIsCorrect -eq $true) {
Write-LogMessage -API 'Standards' -tenant $tenant -message "The tenant Bookings is set correctly to $($Settings.state)" -sev Info
} else {
Write-LogMessage -API 'Standards' -tenant $tenant -message "The tenant Bookings is not set correctly to $($Settings.state)" -sev Alert
}
}

if ($Settings.report -eq $true) {
# Default is not set, not set means it's enabled
if ($null -eq $CurrentState ) { $CurrentState = $true }
Add-CIPPBPAField -FieldName 'BookingsState' -FieldValue $CurrentState -StoreAs bool -Tenant $tenant
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
function Invoke-CIPPStandardCloudMessageRecall {
<#
.FUNCTIONALITY
Internal
#>
param($Tenant, $Settings)

# Input validation
if ([string]::isNullOrEmpty($Settings.state) -or $Settings.state -eq 'Select a value') {
Write-LogMessage -API 'Standards' -tenant $tenant -message 'MessageRecallEnabled: Invalid state parameter set' -sev Error
Exit
}

$CurrentState = (New-ExoRequest -tenantid $Tenant -cmdlet 'Get-OrganizationConfig').MessageRecallEnabled
$WantedState = if ($Settings.state -eq 'true') { $true } else { $false }
$StateIsCorrect = if ($CurrentState -eq $WantedState) { $true } else { $false }

if ($Settings.remediate -eq $true) {
Write-Host 'Time to remediate'
if ($StateIsCorrect -eq $false) {
try {
New-ExoRequest -tenantid $Tenant -cmdlet 'Set-OrganizationConfig' -cmdParams @{ MessageRecallEnabled = $WantedState } -useSystemMailbox $true
Write-LogMessage -API 'Standards' -tenant $tenant -message "Successfully set the tenant Message Recall state to $($Settings.state)" -sev Info
} catch {
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to set the tenant Message Recall state to $($Settings.state). Error: $ErrorMessage" -sev Error
}
} else {
Write-LogMessage -API 'Standards' -tenant $tenant -message "The tenant Message Recall state is already set correctly to $($Settings.state)" -sev Info
}

}

if ($Settings.alert -eq $true) {
if ($StateIsCorrect -eq $true) {
Write-LogMessage -API 'Standards' -tenant $tenant -message "The tenant Message Recall is set correctly to $($Settings.state)" -sev Info
} else {
Write-LogMessage -API 'Standards' -tenant $tenant -message "The tenant Message Recall is not set correctly to $($Settings.state)" -sev Alert
}
}

if ($Settings.report -eq $true) {
# Default is not set, not set means it's enabled
if ($null -eq $CurrentState ) { $CurrentState = $true }
Add-CIPPBPAField -FieldName 'MessageRecall' -FieldValue $CurrentState -StoreAs bool -Tenant $tenant
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
function Invoke-CIPPStandardTeamsMeetingsByDefault {
<#
.FUNCTIONALITY
Internal
#>
param($Tenant, $Settings)

# Input validation
if ([string]::isNullOrEmpty($Settings.state) -or $Settings.state -eq 'Select a value') {
Write-LogMessage -API 'Standards' -tenant $tenant -message 'TeamsMeetingsByDefault: Invalid state parameter set' -sev Error
Exit
}

$CurrentState = (New-ExoRequest -tenantid $Tenant -cmdlet 'Get-OrganizationConfig').OnlineMeetingsByDefaultEnabled
$WantedState = if ($Settings.state -eq 'true') { $true } else { $false }
$StateIsCorrect = if ($CurrentState -eq $WantedState) { $true } else { $false }

if ($Settings.remediate -eq $true) {
Write-Host 'Time to remediate'
if ($StateIsCorrect -eq $false) {
try {
New-ExoRequest -tenantid $Tenant -cmdlet 'Set-OrganizationConfig' -cmdParams @{ OnlineMeetingsByDefaultEnabled = $WantedState } -useSystemMailbox $true
Write-LogMessage -API 'Standards' -tenant $tenant -message "Successfully set the tenant TeamsMeetingsByDefault state to $($Settings.state)" -sev Info
} catch {
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to set the tenant TeamsMeetingsByDefault state to $($Settings.state). Error: $ErrorMessage" -sev Error
}
} else {
Write-LogMessage -API 'Standards' -tenant $tenant -message "The tenant TeamsMeetingsByDefault state is already set correctly to $($Settings.state)" -sev Info
}

}

if ($Settings.alert -eq $true) {
if ($StateIsCorrect -eq $true) {
Write-LogMessage -API 'Standards' -tenant $tenant -message "The tenant TeamsMeetingsByDefault is set correctly to $($Settings.state)" -sev Info
} else {
Write-LogMessage -API 'Standards' -tenant $tenant -message "The tenant TeamsMeetingsByDefault is not set correctly to $($Settings.state)" -sev Alert
}
}

if ($Settings.report -eq $true) {
# Default is not set, not set means it's enabled
if ($null -eq $CurrentState ) { $CurrentState = $true }
Add-CIPPBPAField -FieldName 'TeamsMeetingsByDefault' -FieldValue $CurrentState -StoreAs bool -Tenant $tenant
}

}
2 changes: 1 addition & 1 deletion version_latest.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.7.3
5.7.4

0 comments on commit 0bfa56b

Please sign in to comment.