Create new Team with Azure Function

Occasional Contributor



I currently have an automated process that creates new teams with an Azure Automation Runbook. I'm looking to replace this with an Azure Function but I'm running into some issues trying to connect to Microsoft Teams via the Function.


I think at this point it's a limitation of Azure Functions but I wanted to check to see if others had this issue.


I am able to load the Module just fine (version 1.1.4) into my Azure Function and here is how I am calling the connection:


$svc_pwd = $env:xxxxxxx | ConvertTo-SecureString -AsPlainText -Force
$creds = New-Object -TypeName System.Management.Automation.PSCredential ('', $svc_pwd)

Connect-MicrosoftTeams -Credential $creds
$objOutput = [PSCustomObject]@{
Status = "Failed to Connect to Microsoft Teams"
Message = "$_.Exception.Message"
Write-Error ($objOutput | ConvertTo-Json) -ErrorAction Stop


I've tried numerous other methods but this should in theory work, and works locally.


This is the error messages it's throwing: 

ERROR: password_required_for_managed_user: Password is required for managed user Exception : Type : Microsoft.Open.Teams.CommonLibrary.AadAuthenticationFailedException


Anybody else seen this or have experience connecting to Teams from Azure Functions?

Thanks- Matt

2 Replies



You should store credentials in in a Automation credential asset.


This is what I use in a automation to connect and disconnect.


#Connect to Teams PowerShell
$cred = Get-AutomationPSCredential -Name "azureautoaccount"
$teams = Connect-MicrosoftTeams -Credential $cred

#Disconnect Teams PowerShell



@Linus Cansby 

That is what I am doing in the current Runbook in Azure Automation but that doesn't flow over to Azure Functions. The best case for Azure Functions is to store in an Azure KeyVault which was my plan once I figured out how to fix the current errors.