Connect-MicrosoftTeams Credential "Object reference not set to an instance of an object"

70 views Asked by At

Have a PowerShell scripting issue. Account credentials are stored in Windows Credentials Manager and extracted by the script.

Import-Module MicrosoftTeams    
$Cred = Get-StoredCredential -Target credName
$Creds = New-Object System.Management.Automation.PSCredential ($Cred.UserName, $Cred.Password)
Connect-MicrosoftTeams -Credential $Creds

Script runs fine when manually run (logged in to server with Service Account), yet when called through automation (running under same Service Account) the connection to MicrosoftTeams fails with error "Object reference not set to an instance of an object".

Connection to Teams should work in both scenarios.

Any pointers appreciated.

1

There are 1 answers

0
Matthew Watt On

Additional error logging has shown the automated processing isn't actually retrieving the stored credentials, therefore cannot authenticate to MicrosoftTeams.