Forum Discussion
Run the same Cmdlets for 100 different tenant
Hi,
Any approach will require:
1) Initially manually entering the credentials for each tenant, and,
2) Creating a separate Msol connection to the tenant
Which is what you are doing. Once those credentials are entered and stored, you won't have to manually enter them again obviously
Storing them on disk with Export-CliXml is more secure than plain text passwords but not super secure if those are Global Administrator credentials (it uses the private key machine to encrypt).
Unlike Exchange Online, and SfBO, Connect-MsolService isn't creating a local PS session, so you don't need the Remove-PSSession.
Curtis
The trouble with MSOL cmdlets though is that you don't have a "disconnect" cmdlet, thus if there is something wrong with the new session you are creating, the tenant context will not get switched and you will run the same cmdlets against the previously connected one. Thus I'd recommend using the Azure AD module instead, if possible.
And I fully agree about the storing credentials remark Curtis made, be very careful with that.