Link to home
Start Free TrialLog in
Avatar of Len Kally
Len KallyFlag for United States of America

asked on

Office 365 connect via powershell

I created a script to connect to my Office 365 tenant:

Import-Module MSOnline
$cred = Get-Credential
Connect-MsolService -Credential $cred
$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ 
-Credential $cred -Authentication Basic -AllowRedirection

Import-PSSession $session -AllowClobber



When I run this script a prompt appears and after I enter my credentials, it advises [see attached].  
I do not understand why it says 'credential' not recognized, can anyone help.

Thanks

User generated image
Avatar of Kimputer
Kimputer

I can only replicate this error WHEN I INPUT the wrong credentials. Therefore, your script should work if you remove some lines that are not useful:

 $cred = Get-Credential
 $session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $cred -Authentication Basic -AllowRedirection
 Import-PSSession $session -AllowClobber

Open in new window


Please note there are THREE lines, do not break up the lines (I think yours has a line that starts with "-Credential etc....")
SOLUTION
Avatar of Mark Galvin
Mark Galvin
Flag of United Kingdom of Great Britain and Northern Ireland image

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 Len Kally

ASKER

I am using the correct credentials because I can get in via the web.
Have you followed he steps to connect in my article?
I followed the URL above, and the script above and still get his message.

Keep in mind if I type:  www.portal.office.com,  I can get into the portal, with the same User ID & PW.  But cannot get in via the script above

User generated image
Also where is their a script I can connect, all at once, why do I have to enter credentials twice?

Thanks
SOLUTION
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
I tried the above script and it does not work.
I have full blown privileges for the domain & O365
2015-10-21_08-41-27.png
The script doesn't work because I don't magically know your username and password. You asked for a script that logs in, I cannot log in for you. You have to change the username and password.
@Kimputer - nice script. Just tried it witj my Office 365 Admin and worked like a dream. Going off to edit my Article now!!

@zero000kool
The only admin credentials you need for what you are trying to achieve are Office 365 Admin rights. As Kimputer states you will need to change the "user" to your Office 365 admin user log in and the "pass" to your Office 365 admin password.

If you are still unable to connect can you check, If you lo into the web portal for Office 365 are you able to go into the Admin area at the bottom left of the screen:
User generated image
Thanks
Mark
that is not the issue above, I can log into the portal via the web but not via the command prompt.
ASKER CERTIFIED SOLUTION
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