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

88 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 best solutions below

0
On

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