Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, January 5, 2016 3:01 PM
Hello,
I am trying to connect to Office 365 using PowerShell to manage licenses with a script. I want to use the Connect-MsolService -CurrentCredentails so that the script can run under a service account rather than it prompting for credentials. The script will be run as a scheduled task so if it prompts for credentials it will never work.
When I run Connect-MsolService -CurrentCredentials I get the following error:
Connect-MsolService : An error occurred during authentication. Please retry your operation. If this problem persists,
contact Technical Support.
At line:1 char:1
- Connect-MsolService -CurrentCredential
-
+ CategoryInfo : OperationStopped: (:) [Connect-MsolService], MicrosoftOnlineException
+ FullyQualifiedErrorId : 0x0,Microsoft.Online.Administration.Automation.ConnectMsolService
If I use the cmdlet "Connect-MsolService -Credentials $cred" it prompts me for credentials, I enter my UPN and password and it connects successfully. I have tried running PowerShell as an administrator but the same error still occurs.
If I use the following code
$Username = "username@domain"
$Password = ConvertTo-SecureString ‘password’ -AsPlainText -Force
$LiveCred = New-Object System.Management.Automation.PSCredential $Username, $Password
Connect-MsolService -Credential $LiveCred
It works but this means storing the password in plain text which is bad practice and could pose a security risk.
Can you offer any advice on how to get Connect-MsolService -CurrentCrendentials working?
Thank you
All replies (9)
Tuesday, January 5, 2016 3:24 PM ✅Answered
I am pretty sure that CurrentCredentails means that you want to open another connection ater you are connected to an online service like SharePoint or ExchangeOnline.
In order to find the service you need the full live credential or full MSOL credential .
It also works when you have a hybrid installation and you are logged into a hybrid account.
*** -CurrentCredentials <switch>***
*** If specified, uses the credentials of the currently logged in user to connect to Windows Azure Active Directory. This does not require the user to specify their***
*** credentials explicitly.***
\(ツ)_/
Tuesday, January 5, 2016 3:13 PM
Hi,
From what I see, that switch isn't actually usable in the first place:
http://www.david-homer.blogspot.com/2015/09/connect-msolservice-incorrectly-shows.html
I have no way to test this however, so perhaps someone else will have better information for you.
Wednesday, January 6, 2016 8:44 AM
I'm a bit confused, so the cmdlet either doesn't work or you have to authenticate to MSOnline before you can authenticate with current credentials?
I was hoping to use it in a script to save me having to either save the password in an encrypted form or prompt for credentials :(
Wednesday, January 6, 2016 6:54 PM
I am pretty sure that CurrentCredentails means that you want to open another connection ater you are connected to an online service like SharePoint or ExchangeOnline.
In order to find the service you need the full live credential or full MSOL credential .
It also works when you have a hybrid installation and you are logged into a hybrid account.
*** -CurrentCredentials <switch>***
*** If specified, uses the credentials of the currently logged in user to connect to Windows Azure Active Directory. This does not require the user to specify their***
*** credentials explicitly.***
\(ツ)_/
Tis true..
PS H:\ $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
PS H:\ Connect-MsolService -CurrentCredential
PS H:\
Edit: I take that back, apparently I was already connected. Perhaps this is for future use?
They need to fix the help:-)
PS C:\Windows> Connect-MsolService -CurrentCredentials
Connect-MsolService : A parameter cannot be found that matches parameter name
'CurrentCredentials'.
SYNTAX
Connect-MsolService [-Credential <PSCredential>] [-CurrentCredentials
<switch>] [<CommonParameters>]
Dan
Wednesday, January 6, 2016 7:11 PM
You doubted?
If you install MSOL correctly it can cache the creds and you never have to enter them.
\(ツ)_/
Thursday, January 7, 2016 8:41 AM
Can you explain how jrv?
Thursday, January 7, 2016 1:53 PM
Can you explain how jrv?
Yes . It is just magic. We use magic all of the time in computer science.
I recommend that you start by studying what MSOL is and why O365 is just a different way of packaging Msol.
Also rememner that, in ahybrid setting, you are always sautomatically authenticated lcally and online -- "Integrated Security" maybe?
\(ツ)_/
Friday, November 3, 2017 1:58 PM
I have no idea what is meant by "install MSOL correctly", however here's a method that allows you to store encrypted creds and thus get a script to run without prompting. Which for some people, including me, equates to the same thing.
I wrote this for SMTP but the cred stuff is exactly the same as you need for Connect-MsolService.
https://rcmtech.wordpress.com/2016/03/03/send-smtp-email-with-authentication-from-powershell/
Hopefully that will actually help some people :-)
Friday, November 3, 2017 2:33 PM
I have no idea what is meant by "install MSOL correctly", however here's a method that allows you to store encrypted creds and thus get a script to run without prompting. Which for some people, including me, equates to the same thing.
I wrote this for SMTP but the cred stuff is exactly the same as you need for Connect-MsolService.
https://rcmtech.wordpress.com/2016/03/03/send-smtp-email-with-authentication-from-powershell/
Hopefully that will actually help some people :-)
This has absolutely nothing to do with the discussion. What does mail have to do with connecting to MSOL Are you just making wild guesses? Do you even know what MSOL is?
Search for MSOL (MSOnline CmdLets)?
\(ツ)_/