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

Error
zero000koolAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

KimputerCommented:
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....")
0
Mark GalvinManaging Director / Principal ConsultantCommented:
Hi

If you follow the steps in my article http://www.experts-exchange.com/articles/17522/Access-Office-365-using-Powershell-to-perform-admin-tasks.html you should be fine - as long as you are using the correect Office 365 credentials.

Thanks
Mark
0
zero000koolAuthor Commented:
I am using the correct credentials because I can get in via the web.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Mark GalvinManaging Director / Principal ConsultantCommented:
Have you followed he steps to connect in my article?
0
zero000koolAuthor Commented:
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

Error
0
zero000koolAuthor Commented:
Also where is their a script I can connect, all at once, why do I have to enter credentials twice?

Thanks
0
KimputerCommented:
Without entering credentials:

$username = "user"
$password = "pass"
$secstr = New-Object -TypeName System.Security.SecureString
$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}

$Credential = new-object -typename System.Management.Automation.PSCredential `
         -argumentlist $username, $secstr
		 
$PSSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Credential -Authentication Basic -AllowRedirection
 
Import-PSSession $PSSession

Open in new window


Can you try again with this script (connectionuri slightly different)
Are you logging in with the highest admin account? Which Office365 subscription is it?
0
zero000koolAuthor Commented:
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
0
KimputerCommented:
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.
0
Mark GalvinManaging Director / Principal ConsultantCommented:
@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:
1.JPG
Thanks
Mark
0
zero000koolAuthor Commented:
that is not the issue above, I can log into the portal via the web but not via the command prompt.
0
Mark GalvinManaging Director / Principal ConsultantCommented:
OK, so you cn log into the web portal and open the Admin menu.

Have you installed:
'Microsoft Online Services Sign-In Assistant'
AND
'Windows Azure Active Directory Module for Windows PowerShell'. This can be downloaded here:
Windows Azure Active Directory Module for Windows PowerShell (32-bit)
Windows Azure Active Directory Module for Windows PowerShell (64-bit)

Thanks
Mark
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Office 365

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.