You could use an app password:
(cited from https://www.varonis.com/blog/connect-to-office-365-powershell)
How To Set an App Password for Microsoft 365 and PowerShell
To configure an app password:
- Navigate to https://aka.ms/mfasetup and select the App Passwords menu.
- Select the Create button and give the app password a name to indicate its purpose.
- After clicking Next, the window will display the app password, and you should save it in a password credential manager as you won’t be able to retrieve it.
This will allow your PowerShell script to use your username and app password as a credential to authenticate. Note: You must have app passwords enabled in your tenant.
--------------------------------
If this is helpful please accept answer.