Creating PowerShell Script for auto login in O365 (MS Teams) using MFA - Admin side

AMaDAC 81 Reputation points

The idea is to create a script to automatically login to MS Teams and whenever or someone changes the settings in meeting policy it will triggered an alert or email and also run the script to revert back the changes.

P.S I'm using MFA and please if know a forum or link it will be a great help.

Microsoft Teams
Microsoft Teams
A Microsoft customizable chat-based workspace.
9,584 questions
Microsoft Teams Development
Microsoft Teams Development
Microsoft Teams: A Microsoft customizable chat-based workspace.Development: The process of researching, productizing, and refining new or existing technologies.
3,053 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,455 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Rich Matheisen 45,831 Reputation points

  2. JimmyYang-MSFT 50,446 Reputation points Microsoft Vendor

    Hi @Rich Matheisen ,

    Sorry, I did not find such scripts to convert back the settings for Teams admin center.

    For Teams client, if you want to login automatically, you should click “yes” to store the password for your account when you see the following page:


    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.

  3. Kartheek Raparthy 1 Reputation point

    Please use below script for auto login to teams.

    $username = "<username>"
    $passwd = "<password>"
    $secpasswd = ConvertTo-SecureString -String $passwd -AsPlainText -Force
    $cred = New-Object Management.Automation.PSCredential ($username, $secpasswd)
    Connect-MicrosoftTeams -Credential $cred

    For meeting policy change alerts you can create Alert in audit logs. This is available in azure security and compliance. you can choose recipient email address.