How to create powershell to schedule task script Connect-MicrosoftTeams without credentials+ MFA enabled

MS 426 Reputation points
2022-09-18T16:31:06.217+00:00

Hi,

How to run the PowerShell script through a Task scheduler when the account is MFA enabled.
We have a script manually running on a weekly basis to export the user reports,
Our requirements is, the task should automatically start the script, is there a way to bypass the Login process, which can be done in the script during the script ?

Without certs or GRAPH , is there any solution/ script to login to O365 automatically to run the scrip.

Thanks in Advance.

Regads,
MS

Windows for business Windows Server User experience PowerShell
Microsoft Teams Microsoft Teams for business Other
{count} votes

2 answers

Sort by: Most helpful
  1. Dillon Silzer 57,826 Reputation points Volunteer Moderator
    2022-09-18T18:22:57.643+00:00

    Hi @MS

    If you don't want to use certs or graph you can try going down the app password route. You will need to have this enabled for your tenant otherwise you will not see the functionality. I am not 100% sure app passwords work for PowerShell as it's not really secure, but you can try. (since you didn't mention what type of PowerShell scripts you are trying to run).

    Manage app passwords for two-step verification

    https://support.microsoft.com/en-us/account-billing/manage-app-passwords-for-two-step-verification-d6dc8c6d-4bf7-4851-ad95-6d07799387e9

    If this doesn't work for the type of PS script you are trying to run, you will have to default to using Certificates (which isn't that hard to setup/manage).

    ---------------------------------

    If this is helpful please accept answer.

    0 comments No comments

  2. Schiffer Dustin 10 Reputation points
    2024-02-22T13:21:38.2866667+00:00

    I´ve run into the same situation when it comes to Teams and thanks to @Dillon Silzer who point me to the possible solution... -> https://learn.microsoft.com/en-us/microsoftteams/teams-powershell-application-authentication Regards!

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.