0

We need to create email aliases from an API call. It doesn't appear that the Microsoft Graph has this option. We were looking to do this in an Azure Function with Powershell until we have another API option to make it work.

using namespace System.Net

# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)

Install-Module ExchangeOnlineManagement -Force
Connect-ExchangeOnline -CertificateThumbPrint "{thumbprint}" -AppID "{appid}" -Organization "org.onmicrosoft.com"


#Connect-ExchangeOnline

# Write to the Azure Functions log stream.
Write-Host "PowerShell HTTP trigger function processed a request."

# Interact with query parameters or the body of the request.
$name = $Request.Query.Name
if (-not $name) {
    $name = $Request.Body.Name
}

$user = $Request.Query.User
if (-not $user) {
    $user = $Request.Body.User
}

Set-Mailbox $user -EmailAddresses @{add="{"+$name+"@yourorg.com"}

$body = "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."

if ($name) {
    $body = "Hello, $user. This HTTP triggered function executed successfully."
}

# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
    StatusCode = [HttpStatusCode]::OK
    Body = $body
})

I'm working on this now. But anyone have luck with doing this? Or have a better way to handle email alias creation with an API?

I have the requirements file set with this as well.

# This file enables modules to be automatically managed by the Functions service.
# See https://aka.ms/functionsmanageddependency for additional information.
#
@{
    # For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'. 
    # To use the Az module in your function app, please uncomment the line below.
    # 'Az' = '6.*'
     'ExchangeOnlineManagment' = '3.*'
}

It appears the the app registration with the thumbprint is not working. Is there some type of limitation there?

I have the app registered with the cert and have the thumbprint and cert in those fields.

Connect-ExchangeOnline -CertificateThumbPrint "{thumbprint}" -AppID "{appid}" -Organization "org.onmicrosoft.com"

[Error] EXCEPTION: No certificate found for the given CertificateThumbprint

Eric
  • 958
  • 1
  • 11
  • 28

1 Answers1

0

We ended up using managed identity in the runbook and setting permissions to exchange in azure.

Eric
  • 958
  • 1
  • 11
  • 28