Connect-MicrosoftTeams Errors

Brass Contributor

I have a powershell script that automatically creates a group when someone creates a SharePoint list item.  Now, I want to set it up to create a Team instead. I'm running the following code trying to connect to Microsoft Teams with the new MicrosoftTeams powershell module. 

 

$username = 'myuser@mydomain.com';
$pwdContents = *****
$securePassword =  convertto-securestring($pwdContents) -key (1..16);
$credential = New-Object System.Management.Automation.PSCredential($username, $securePassword)

Connect-MicrosoftTeams -AccountId $username -Credential $credential;

I'm getting this error

 

 

Connect-MicrosoftTeams : One or more errors occurred.: AADSTS75005: The request is not a valid SAML 2.0 protocol
message.
Trace ID: 82a820ba-19de-4cf2-87f4-61c21d8d3100
Correlation ID: 07667e10-a183-4dc3-8b21-8cf79b172f3e
Timestamp: 2018-02-06 20:33:18Z
At line:1 char:5
+     Connect-MicrosoftTeams -Credential $credential;
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : AuthenticationError: (:) [Connect-MicrosoftTeams], AadAuthenticationFailedException
    + FullyQualifiedErrorId : Connect-MicrosoftTeams,Microsoft.Open.Teams.CommonLibrary.ConnectMicrosoftTeams

Connect-MicrosoftTeams : One or more errors occurred.
At line:1 char:5
+     Connect-MicrosoftTeams -Credential $credential;
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : AuthenticationError: (:) [Connect-MicrosoftTeams], AggregateException
    + FullyQualifiedErrorId : Connect-MicrosoftTeams,Microsoft.Open.Teams.CommonLibrary.ConnectMicrosoftTeams

Connect-MicrosoftTeams : AADSTS75005: The request is not a valid SAML 2.0 protocol message.
Trace ID: 82a820ba-19de-4cf2-87f4-61c21d8d3100
Correlation ID: 07667e10-a183-4dc3-8b21-8cf79b172f3e
Timestamp: 2018-02-06 20:33:18Z
At line:1 char:5
+     Connect-MicrosoftTeams -Credential $credential;
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : AuthenticationError: (:) [Connect-MicrosoftTeams], AdalServiceException
    + FullyQualifiedErrorId : Connect-MicrosoftTeams,Microsoft.Open.Teams.CommonLibrary.ConnectMicrosoftTeams

Connect-MicrosoftTeams :  Response status code does not indicate success: 400 (BadRequest).
At line:1 char:5
+     Connect-MicrosoftTeams -Credential $credential;
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : AuthenticationError: (:) [Connect-MicrosoftTeams], HttpRequestException
    + FullyQualifiedErrorId : Connect-MicrosoftTeams,Microsoft.Open.Teams.CommonLibrary.ConnectMicrosoftTeams

Connect-MicrosoftTeams : {"error":"invalid_request","error_description":"AADSTS75005: The request is not a valid SAML
2.0 protocol message.\r\nTrace ID: 82a820ba-19de-4cf2-87f4-61c21d8d3100\r\nCorrelation ID:
07667e10-a183-4dc3-8b21-8cf79b172f3e\r\nTimestamp: 2018-02-06 20:33:18Z","error_codes":[75005],"timestamp":"2018-02-06
20:33:18Z","trace_id":"82a820ba-19de-4cf2-87f4-61c21d8d3100","correlation_id":"07667e10-a183-4dc3-8b21-8cf79b172f3e"}
At line:1 char:5
+     Connect-MicrosoftTeams -Credential $credential;
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : AuthenticationError: (:) [Connect-MicrosoftTeams], Exception
    + FullyQualifiedErrorId : Connect-MicrosoftTeams,Microsoft.Open.Teams.CommonLibrary.ConnectMicrosoftTeams

Connect-MicrosoftTeams : One or more errors occurred.: AADSTS75005: The request is not a valid SAML 2.0 protocol
message.
Trace ID: 82a820ba-19de-4cf2-87f4-61c21d8d3100
Correlation ID: 07667e10-a183-4dc3-8b21-8cf79b172f3e
Timestamp: 2018-02-06 20:33:18Z
At line:1 char:5
+     Connect-MicrosoftTeams -Credential $credential;
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Connect-MicrosoftTeams], AadAuthenticationFailedException
    + FullyQualifiedErrorId : Microsoft.Open.Teams.CommonLibrary.AadAuthenticationFailedException,Microsoft.Open.Teams
   .CommonLibrary.ConnectMicrosoftTeams

I've also tried using an access token, which appears to get me connected but none of the subsequent commands work.

$appid = "xxxxxxx";
$client_secret = "xxxxxx";
$tenant_id = "xxxxxx";
$resource = "https://graph.microsoft.com";

$username = 'myusername@mydomain.com'
$conn = connect-pnpmicrosoftgraph -AppId $appid -AppSecret $client_secret -AADDomain "huroncg.onmicrosoft.com" -Verbose;
$access_token = Get-PnPAccessToken;
Connect-MicrosoftTeams -AccountId $username -AadAccessToken $access_token;

When I do this, the connection appears to work, but when I run something like get-team, I get the dreaded 'Object not set to an instance of an object error'

PS > get-team
get-team : Object reference not set to an instance of an object.
At line:1 char:1
+ get-team
+ ~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-Team], NullReferenceException
    + FullyQualifiedErrorId : System.NullReferenceException,Microsoft.TeamsCmdlets.PowerShell.Custom.GetTeam

What am I doing wrong?

 

 

6 Replies

I think the problem is that you are trying to do both accountid and credentials.

have you tried only just to run 

Connect-MicrosoftTeams

 and are you running the 0.9.1 commands?

Yes, running version 0.9.1.  I can do connect-microsoftteams and that works but I'm working on an unattended script, so leaving connect-microsoftteams with no credentials won't be an option.

I ended up opening a ticket with Microsoft.  It turns out that my organization's Ping sign in system doesn't support SAML 2.0, which the Teams PowerShell API requires.  We will need to upgrade to be able to do what I'm attempting to do.

More specifically, can anyone confirm if the entire protocol needs to be SAML 2.0, or just the token?  Since PowerShell seems to be using the WS-Trust flow for Teams, would changing the token to SAML 2.0 (it defaults to 1.0) be sufficient?

@Robbert van Andel 

Have you tried?
Connect-MicrosoftTeams -AccountId $userEmail -MsAccessToken $token -AadAccessToken $token

Just give in the token everywhere you can :)

After that, I can call Get-Team and get a list of all Teams...

@Pascal Hohensträter

And this token comes from where exactly?