rickjames Posted September 4, 2018 Posted September 4, 2018 Afternoon all. I've got the following script below to help me connect to a few multiple O365 services rather than authenticate every single time $adminName = "[email protected]" $Password = Get-Content "C:\users\myname\Desktop\credentials.txt" | ConvertTo-SecureString $Credential = new-object -typename system.management.automation.PSCredential -Argumentlist $adminname,$Password Import-Module MSOnline Connect-MsolService -Credential $Credential $ExchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Credential -Authentication Basic -AllowRedirection Import-PSSession $ExchangeSession -AllowClobber Import-Module SkypeOnlineConnector $sfboSession = New-CsOnlineSession -Credential $Credential Import-PSSession $sfboSession Import-Module Microsoft.Online.SharePoint.PowerShell However, it's spitting this out Connect-MsolService : Sequence contains no elements At line:1 char:1 + Connect-MsolService -Credential $Credential + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OperationStopped: ( [Connect-MsolService], InvalidOperationException + FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.Online.Administration.Automation.ConnectMsolService Any ideas as to why? I'm a global admin, MFA isn't enabled or anything silly. Bit stumped, if I'm being honest! Modules also installed AFAIK
Steve21 Posted September 4, 2018 Posted September 4, 2018 (edited) You have a lowercase vs uppercase mix in your variables vs the credential line. Might want to fix one and retry it before digging too much into it -Edit to clarify $adminName vs $adminname Does it work if you just do it like this for a test (not that it should make much difference but it's from a script we had): $adminName = "[email protected]" $Password = ConvertTo-SecureString "Password" -AsPlainText -Force $Credential = New-Object -TypeName PSCredential -Argumentlist $adminName, $Password Import-Module MSOnline Connect-MsolService -Credential $Credential Steve Edited September 4, 2018 by Steve21
free780 Posted September 4, 2018 Posted September 4, 2018 Also Azure/Office365 is having a lot of issues at the moment.
rickjames Posted September 4, 2018 Author Posted September 4, 2018 Cheers both, will have a look. Just to clarify; the credentials.txt file is an encrypted file, no bad practice with that one
Steve21 Posted September 4, 2018 Posted September 4, 2018 Aye but I mean just to test whether it's a script issue or bigger thing like the account not working permissions wise. But if you are using the encrypted file method are you using the same user and computer you encrypted it on to run the script? DAPI wouldn't work if you had for example the password encrypted as yourself and a script run by techie1 as he couldn't decrypt it Steve
rickjames Posted September 6, 2018 Author Posted September 6, 2018 You have a lowercase vs uppercase mix in your variables vs the credential line. Might want to fix one and retry it before digging too much into it -Edit to clarify $adminName vs $adminname Does it work if you just do it like this for a test (not that it should make much difference but it's from a script we had): $adminName = "[email protected]" $Password = ConvertTo-SecureString "Password" -AsPlainText -Force $Credential = New-Object -TypeName PSCredential -Argumentlist $adminName, $Password Import-Module MSOnline Connect-MsolService -Credential $Credential Steve Tried this and it brought up a popup box asking for my credentials (which I'd rather not happen, but not the end of the world). Connects fine, but naturally don't want any passwords listed. Something wrong with that credentials file then?
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now