Jump to content

Recommended Posts

Posted

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

Posted (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 by Steve21
Posted

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

Posted
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?

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...