Skip to content

Commit

Permalink
converted to function
Browse files Browse the repository at this point in the history
  • Loading branch information
KelvinTegelaar committed Jul 17, 2023
1 parent 00e8e1d commit 7f6a228
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
8 changes: 2 additions & 6 deletions ExecConverttoSharedMailbox/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,10 @@ Write-Host "PowerShell HTTP trigger function processed a request."
# Interact with query parameters or the body of the request.
Try {
$MailboxType = if ($request.query.ConvertToUser -eq 'true') { "Regular" } else { "Shared" }
$tenantfilter = $Request.Query.TenantFilter
New-ExoRequest -tenantid $TenantFilter -cmdlet "Set-mailbox" -cmdParams @{Identity = $request.query.id; type = $MailboxType }

$Results = [pscustomobject]@{"Results" = "Successfully converted $($request.query.id)." }
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $($tenantfilter) -message "Converted mailbox $($request.query.id)" -Sev "Info"
$ConvertedMailbox = Set-CIPPMailboxType -userid $Request.query.id -tenantFilter $Request.query.TenantFilter -APIName $APINAME -ExecutingUser $request.headers.'x-ms-client-principal' -MailboxType $MailboxType
$Results = [pscustomobject]@{"Results" = "$ConvertedMailbox" }
}
catch {
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $($tenantfilter) -message "Convert to shared mailbox failed: $($_.Exception.Message)" -Sev "Error"
$Results = [pscustomobject]@{"Results" = "Failed to convert $($request.query.id) - $($_.Exception.Message)" }
}
# Associate values to output bindings by calling 'Push-OutputBinding'.
Expand Down
1 change: 1 addition & 0 deletions Modules/CIPPCore/Public/Set-CIPPMailboxType.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function Set-CIPPMailboxType {
try {
$Mailbox = New-ExoRequest -tenantid $TenantFilter -cmdlet "Set-mailbox" -cmdParams @{Identity = $userid; type = $MailboxType } -Anchor $username
Write-LogMessage -user $ExecutingUser -API $APIName -message "Converted $($username) to a $MailboxType mailbox" -Sev "Info" -tenant $TenantFilter
if (!$username) { $username = $userid }
return "Converted $($username) to a $MailboxType mailbox"
}
catch {
Expand Down

0 comments on commit 7f6a228

Please sign in to comment.