question

DanielBecker-2339 avatar image
0 Votes"
DanielBecker-2339 asked JayaC-MSFT commented

Connecting to Microsoft Teams through non-interactive powershell script

I am trying to write an azure function in PowerShell to connect to a Microsoft Teams account:


using namespace System.Net

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

# Write to the Azure Functions log stream.
Write-Host "Running teams account setup."

[string]$userName = 'xxx'
[string]$userPassword = 'xxx'
[securestring]$secStringPassword = ConvertTo-SecureString $userPassword -AsPlainText -Force
Write-Host ($secStringPassword | Format-Table | Out-String)
[pscredential]$credentials = New-Object System.Management.Automation.PSCredential ($userName, $secStringPassword)
Write-Host ($credentials | Format-Table | Out-String)
Connect-MicrosoftTeams -Credential $credentials


The error message I'm getting is essentially: ERROR: password_required_for_managed_user: Password is required for managed user

I read that it might be necessary to replace -Credentials with -Identity, but I can't find any documentation on how to implement that.

azure-functionsoffice-teams-app-dev
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

To solve this issue, we have a third option of storing encrypted credentials to a file on the computer. The PowerShell script uses the encrypted password from the file to create a credential object. please go through below links. link1 Link2

0 Votes 0 ·
JayaC-MSFT avatar image
1 Vote"
JayaC-MSFT answered JayaC-MSFT commented

Hello @DanielBecker-2339, it seems to be an issue : https://github.com/MicrosoftDocs/office-docs-powershell/issues/5950
Our core team will be rolling out the fix soon. I will update this thread as soon as there is any development regarding this.

If this helps, please "Accept the Answer" and "Up-vote" so that it could help others in the community.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @JayaC-MSFT, would you mind giving us an update regarding when the fixes for authentication will be available, or a link to the issue to monitor the progress? As everyone is well aware, theoretically, the SkypeOnlineConnector will stop working in a couple of days, but the Teams replacement is still broken in v2.3.1 (it's been this way for at least a couple of months if we look at the dates on this thread) and some of us relying on this functionality are running out of options.

Just to be fair, I must admit that my issue is not exactly the same as I'm trying to use the device_code flow (or tokens) to authenticate, but clearly there is something wrong with the authentication implementations, and I really don't know where to look for answers...

Kind regards

0 Votes 0 ·
SharonZhao-MSFT avatar image
0 Votes"
SharonZhao-MSFT answered SharonZhao-MSFT commented

@DanielBecker-2339,

As we are mainly responsible for general issue of Microsoft Teams, your question which is more related to script is not in our scope. Thanks for your understanding.

The following script is for your reference. I have tested it in my lab. It works well.

 $User = "xxx@contoso.com"
 $PassWord = ConvertTo-SecureString -String "YourPassword" -AsPlainText -Force
 $UserCredential = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $User, $PassWord
 import-module microsoftteams
 Connect-MicrosoftTeams -Credential $UserCredential -AccountId $User


If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Sharon, thank you for the feedback. Could you maybe point me to a better place to ask my question?

Did you run your script as an Azure function? It works perfectly fine if you run it locally, just not in the function context.

0 Votes 0 ·

@DanielBecker-2339,
No, I did not run the script as an Azure function.
I will add office-teams-app-dev tag for this thread. Hope you get better response.
Have a nice day!

1 Vote 1 ·