Carl Billington
asked on
Logon to Office 365 via command line without prompting for credentials
Is it possible to logon to Office 365 from command line without prompting for credentials? I would like credentials to be a part of the script.
Thank you.
Thank you.
ASKER
Thanks for your response. Am I executing this wrong?
########################################################################################
###Script : To Execute PowerShell script with other credentials without prompts
###Developer : Chendrayan Venkatesan
###Company : Tata Consultancy Service
########################################################################################
#SharePoint Admin Account
$SPAdmin = "name@myemailaddress.com.au"
$Password = Get-Content C:\securestring.txt | convertto-securestring
$Credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $SPAdmin, $Password
Get-WmiObject -Class Win32_Service -ComputerName "Server" -Filter "Name='ServiceName'" -Credential $Credential
$LiveCred = Get-Credential
Connect-MSOLService -Credential $cred
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi, thanks for your reply. Step 1 asked for your credentials. Is there any way we can extract this information from a text file so that you do not need to input them?
You do realize you have to STORE those credentials to the text file first? This is what steps 1 and 2 do.
You do not need to include those steps in the script file. But you need to run them at least once on each machine you will be running the script from.
You do not need to include those steps in the script file. But you need to run them at least once on each machine you will be running the script from.
ASKER
Hi, on the final step, as soon as I run;
I completed the other steps successfully.
Connect-MSOLService -Credential $cred
I am prompted for a username and password?I completed the other steps successfully.
You arent using the step to READ the stored credentials, the path you have given is wrong or the variable names don't match.
ASKER
My bad! All good!
ASKER
Awesome!
Or here: https://gallery.technet.microsoft.com/scriptcenter/Execute-PowerShell-Script-38881dce