Forum Discussion
Prabhakar Sastry
Feb 05, 2018Brass Contributor
Authenticating to O365 using Powershell without MFA
Hi All,
We've got ADFS and SSO enabled without MFA for the Admins, strong authentication is enabled and when trying to connect via PowerShell was able to connect when try to give the credentials ma...
Pablo R. Ortiz
Feb 05, 2018Iron Contributor
If you want to store credentials and avoid having to type username/password every time you run the script, do the following:
1. Run this line only once, to store encrypted password of "admin@yourdomain.com":
Read-Host -assecurestring | convertfrom-securestring | out-file C:\string.txt
2. Then put the following lines at the beginning of your script:
$password = Get-Content 'C:\string.txt' | ConvertTo-SecureString $username = "admin@yourdomain.com" $credObject = New-Object System.Management.Automation.PSCredential -ArgumentList $username, $password Connect-MsolService -Credential $credObject
Deleted
Feb 05, 2018If you want to store credentials please use the credential manager instead of a txt file which is like putting your credentials open to the internet
- Pablo R. OrtizFeb 05, 2018Iron Contributor
well, storing encrypted password in C:\ isn't exposing anything to the internet, but yes, you could also store credentials in credential manager, with a name (let's say O365), install the module and import your credentials:
Install-Module -Name CredentialManager $Credentials = Get-StoredCredential -Target O365 Connect-msolService -Credential $Credentials