question

DanielBecker-2339 avatar image
0 Votes"
DanielBecker-2339 asked ·

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
10 |1000 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 ·
SharonZhao-MSFT avatar image
0 Votes"
SharonZhao-MSFT answered ·

@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 ·
10 |1000 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 ·
JayaC-MSFT avatar image
1 Vote"
JayaC-MSFT answered ·

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.

·
10 |1000 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.