Set-ExecutionPolicy RemoteSigned (ONLY ONCE)
$credential = Get-Credential
Import-Module MsOnline
Connect-MsolService -Credential $credential
Get-MsolUser (use this to confirm your session)
Unfortunately it pops up asking for the username and password. What I’d like to be able to do is save the username and password so I’m not prompted for it.
there are several methods to achieve this, however, this is rather difficult to do securely.
you can include credentials in scripts in plaintext (BAD IDEA!!)
with a bit more work you can encrypt the passwords, there are various examples online for how to do this
if you are just trying to connect random powershell sessions, you could include the connection strings in your powershell profile, and then generally only be prompted for the credentials when starting a session, or executing a command when the service has disconnected.
i guess the answer i would give will depend on exactly how you are intending to utilize the session
Hi David, thanks for the quick response. The primary reason I’m looking to do it is because as a service provider I am often having to do password reset’s for people and I have to log onto the portal for each account and then reset it…it takes time and is tedious. I was thinking there has to be a faster way to do it by saving the creds in the script. Does that help?
Awesome! Thanks so much for your help. I’ve been working on this behind the scenes and just got around to actually testing it now and it works great. Once again thank you.