Connect-MicrosoftTeams w/ service acct

I searched and the only thread that came up was MS Teams using Managed Identity

I am trying to Connect-MicrosoftTeams from a PSU script with a service account. On the PSU server, I can connect via Powershell terminal using the service account credentials, but I can’t seem to get it to work within a script. (I need to connect to configure numerous attributes that are not accessible via Graph API.)

I’ve created a Secret variable, teams_svc_acct, with the username and password. Snippet of script:

Import-Module MicrosoftTeams
Connect-MicrosoftTeams -Credential $Secret:teams_svc_acct

And this results in:

Error executing job: Failed to login user (1385). System.ComponentModel.Win32Exception (1385): Logon failure: the user has not been granted the requested logon type at this computer.

Appreciate any suggestions.

Product: PowerShell Universal
Version: 3.5.5

Replying to myself for posterity: We figured this out. After going through the setup of the service account and configuring MFA bypass, using this service account to manage our Teams environment is simple. Create a vaulted/secret variable for the service acct name and pwd, then reference that either as a function in scripts; or script it and call that script from other scripts.

# Connect to Teams
Function Connect-online ()
    {
    Param ()
    $Username = (Get-ChildItem "Secret:teams_svc_acct").username
    $passwd = (Get-ChildItem "Secret:teams_svc_acct").password 
    $credential = New-Object System.Management.Automation.PsCredential($Username,$passwd)
    Import-Module MicrosoftTeams
    Connect-MicrosoftTeams -Credential $credential
}
Connect-online | Out-Null