Skip to content

Commit

Permalink
Multiple Changes
Browse files Browse the repository at this point in the history
Added Soft Deleted Mailboxes Scripted Alert
Added additional select-object to ListMailboxes to be used with the Soft Deleted Mailboxes Alert
Added SetAuthMethod function to be used on the new Auth Methods page.
  • Loading branch information
BNWEIN committed Jul 2, 2024
1 parent 2d3414c commit 2192b11
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function Get-CIPPAlertSoftDeletedMailboxes {
<#
.FUNCTIONALITY
Entrypoint
#>
[CmdletBinding()]
Param (
[Parameter(Mandatory = $false)]
[Alias('input')]
$InputValue,
$TenantFilter
)

$Select = 'ExchangeGuid,ArchiveGuid,WhenSoftDeleted,UserPrincipalName,IsInactiveMailbox'

try {
$SoftDeletedMailBoxes = New-ExoRequest -tenantid $TenantFilter -cmdlet 'get-mailbox' -cmdParams @{SoftDeletedMailbox = $true} -Select $Select | Select-Object ExchangeGuid, ArchiveGuid, WhenSoftDeleted, @{ Name = 'UPN'; Expression = { $_.'UserPrincipalName' } }, IsInactiveMailbox

# Filter out the mailboxes where IsInactiveMailbox is $true
$AlertData = $SoftDeletedMailBoxes | Where-Object { $_.IsInactiveMailbox -ne $true }

# Write the alert trace with the filtered data
Write-AlertTrace -cmdletName $MyInvocation.MyCommand -tenantFilter $TenantFilter -data $AlertData

} catch {
Write-AlertMessage -tenant $($TenantFilter) -message "Failed to check for soft deleted mailboxes in $($TenantFilter): $(Get-NormalizedError -message $_.Exception.message)"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
function Invoke-SetAuthMethod {
<#
.FUNCTIONALITY
Entrypoint
.ROLE
Tenant.Administration.ReadWrite
#>
Param(
$Request,
$TriggerMetadata
)

$APIName = "Set Authentication Policy"
$state = if ($Request.Body.state -eq 'enabled') { $true } else { $false }
$Tenantfilter = $Request.Body.TenantFilter

try {
Set-CIPPAuthenticationPolicy -Tenant $Tenantfilter -APIName $APIName -AuthenticationMethodId $($Request.Body.Id) -Enabled $state
$StatusCode = [HttpStatusCode]::OK
$SuccessMessage = "Authentication Policy for $($Request.Body.Id) has been set to $state"
} catch {
$ErrorMsg = Get-NormalizedError -message $($_.Exception.Message)
$SuccessMessage = "Function Error: $($_.InvocationInfo.ScriptLineNumber) - $ErrorMsg"
$StatusCode = [HttpStatusCode]::BadRequest
}

# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = $StatusCode
Body = [pscustomobject]@{'Results' = "$SuccessMessage" }
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Function Invoke-ListMailboxes {
# Interact with query parameters or the body of the request.
$TenantFilter = $Request.Query.TenantFilter
try {
$Select = 'id,ExchangeGuid,ArchiveGuid,UserPrincipalName,DisplayName,PrimarySMTPAddress,RecipientType,RecipientTypeDetails,EmailAddresses,WhenSoftDeleted'
$Select = 'id,ExchangeGuid,ArchiveGuid,UserPrincipalName,DisplayName,PrimarySMTPAddress,RecipientType,RecipientTypeDetails,EmailAddresses,WhenSoftDeleted,IsInactiveMailbox'
$ExoRequest = @{
tenantid = $TenantFilter
cmdlet = 'Get-Mailbox'
Expand Down

0 comments on commit 2192b11

Please sign in to comment.