Skip to content

Commit

Permalink
Fix exchange connectors
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnDuprey committed Jan 7, 2025
1 parent 83cb46a commit 41eb644
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,22 @@ Function Invoke-EditExConnector {
param($Request, $TriggerMetadata)

$APIName = $TriggerMetadata.FunctionName
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug'
$Tenantfilter = $request.Query.tenantfilter


$Params = @{
Identity = $request.query.guid
}

Write-LogMessage -user $Request.Headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug'
$Tenantfilter = $request.Query.tenantfilter ?? $Request.Body.tenantfilter
try {
$state = if ($request.query.state -eq 'enable') { $true } else { $false }
$Params = @{ Identity = $request.query.GUID; Enabled = $state }
$GraphRequest = New-ExoRequest -tenantid $Tenantfilter -cmdlet "Set-$($Request.query.Type)Connector" -cmdParams $params -UseSystemMailbox $true
$Result = "Set Connector $($Request.query.guid) to $($request.query.State)"
$ConnectorState = $Request.Query.State ?? $Request.Body.State
$State = if ($ConnectorState -eq 'enable') { $true } else { $false }
$Guid = $Request.Query.GUID ?? $Request.Body.GUID
$type = $Request.Query.Type ?? $Request.Body.Type
$Params = @{
Identity = $Guid
Enabled = $State
}
$null = New-ExoRequest -tenantid $Tenantfilter -cmdlet "Set-$($Type)Connector" -cmdParams $params -UseSystemMailbox $true
$Result = "Set Connector $($Guid) to $($ConnectorState)"
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $tenantfilter -message "Set Connector $($Request.query.guid) to $($request.query.State)" -sev 'Info'
}
catch {
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $tenantfilter -message "Failed setting Connector $($Request.query.guid) to $($request.query.State). Error:$($_.Exception.Message)" -Sev 'Error'
} catch {
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $tenantfilter -message "Failed setting Connector $($Guid) to $($ConnectorState). Error:$($_.Exception.Message)" -Sev 'Error'
$ErrorMessage = Get-NormalizedError -Message $_.Exception
$Result = $ErrorMessage
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ Function Invoke-ListExConnectorTemplates {
$GUID = $_.RowKey
$Direction = $_.direction
$data = $_.JSON | ConvertFrom-Json
$data | Add-Member -NotePropertyName 'GUID' -NotePropertyValue $GUID
$data | Add-Member -NotePropertyName 'cippconnectortype' -NotePropertyValue $Direction
$data | Add-Member -NotePropertyName 'GUID' -NotePropertyValue $GUID -Force
$data | Add-Member -NotePropertyName 'cippconnectortype' -NotePropertyValue $Direction -Force
$data
} | Sort-Object -Property displayName

Expand Down
16 changes: 8 additions & 8 deletions Modules/CIPPCore/Public/Invoke-RemoveExConnector.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ Function Invoke-RemoveExConnector {
$APIName = $TriggerMetadata.FunctionName
$User = $request.headers.'x-ms-client-principal'
Write-LogMessage -user $User -API $APINAME -message 'Accessed this API' -Sev 'Debug'
$Tenantfilter = $request.Query.tenantfilter

$Tenantfilter = $request.Query.tenantfilter ?? $Request.Body.tenantfilter
$Type = $Request.Query.Type ?? $Request.Body.Type
try {

$Params = @{ Identity = $request.query.GUID }
$null = New-ExoRequest -tenantid $Tenantfilter -cmdlet "Remove-$($Request.query.Type)Connector" -cmdParams $params -useSystemMailbox $true
$Result = "Deleted $($Request.query.guid)"
Write-LogMessage -user $User -API $APIName -tenant $tenantfilter -message "Deleted transport rule $($Request.query.guid)" -sev Debug
$Guid = $Request.Query.GUID ?? $Request.Body.GUID
$Params = @{ Identity = $Guid }
$null = New-ExoRequest -tenantid $Tenantfilter -cmdlet "Remove-$($Type)Connector" -cmdParams $params -useSystemMailbox $true
$Result = "Deleted $($Guid)"
Write-LogMessage -user $User -API $APIName -tenant $tenantfilter -message "Deleted transport rule $($Guid)" -sev Debug
} catch {
$ErrorMessage = Get-CippException -Exception $_
Write-LogMessage -user $User -API $APIName -tenant $tenantfilter -message "Failed deleting transport rule $($Request.query.guid). Error:$($ErrorMessage.NormalizedError)" -Sev Error -LogData $ErrorMessage
Write-LogMessage -user $User -API $APIName -tenant $tenantfilter -message "Failed deleting transport rule $($Guid). Error:$($ErrorMessage.NormalizedError)" -Sev Error -LogData $ErrorMessage
$Result = $ErrorMessage.NormalizedError
}
# Associate values to output bindings by calling 'Push-OutputBinding'.
Expand Down
4 changes: 2 additions & 2 deletions Modules/CIPPCore/Public/Invoke-RemoveExConnectorTemplate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ Function Invoke-RemoveExConnectorTemplate {
$User = $request.headers.'x-ms-client-principal'
Write-LogMessage -user $User -API $APINAME -message 'Accessed this API' -Sev 'Debug'

$ID = $request.query.id
$ID = $Request.Query.ID ?? $Request.Body.ID
try {
$Table = Get-CippTable -tablename 'templates'
$Filter = "PartitionKey eq 'ExConnectorTemplate' and RowKey eq '$id'"
$Filter = "PartitionKey eq 'ExConnectorTemplate' and RowKey eq '$ID'"
$ClearRow = Get-CIPPAzDataTableEntity @Table -Filter $Filter -Property PartitionKey, RowKey
Remove-AzDataTableEntity -Force @Table -Entity $clearRow
Write-LogMessage -user $User -API $APINAME -message "Removed Exchange Connector Template with ID $ID." -Sev 'Info'
Expand Down

0 comments on commit 41eb644

Please sign in to comment.