Link to home
Start Free TrialLog in
Avatar of Anthony K O365
Anthony K O365Flag for United States of America

asked on

Pass-through User and Password Credential for O365 Cloud session

I have a script that creates session to Office 365. However I need a way to include the credentials without always having to type it in. Can someone assist?

thanks!
Avatar of John Salle
John Salle

I'm assuming you're talking about connecting to the PowerShell back end of Office 365. Are you set up with standalone "In-Cloud" accounts, or using ADFS/DirSync?
Avatar of Anthony K O365

ASKER

Using Dirsync
ASKER CERTIFIED SOLUTION
Avatar of John Salle
John Salle

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Vasil Michev (MVP)
Using the above method has the downside of having the credentials viewable in plain text, so you might consider storing them securely instead:

$x = Get-Credential
$x.Password | ConvertFrom-SecureString | Set-Content C:\password.txt

Open in new window


Then simply encrypt the password.txt file. To reuse the credentials in the script, include this:

$encrypted = Get-Content C:\password.txt | ConvertTo-SecureString
$credential = New-Object System.Management.Automation.PsCredential("user@domain.com", $encrypted)

Import-Module MSOnline
Connect-MsolService -Credential $credential

Open in new window


And so on for the rest of the connections.
this worked ideally.

thanks!