How to manage Office365 with Powershell, Exchange

Hello, i am just wondering how to use powershell commandlets to manage office365 Exchange ?

I am able to create the session and remove the session but i cannot query anything like querying the mailboxes...

Thanks for your help,
namergSystems AdministratorAsked:
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.

Jeremy WeisingerSenior Network Consultant / EngineerCommented:
timgreen7077Exchange EngineerCommented:
please share the cmdlets you are using to create the session, because if you are connecting correctly to the session and you have the correct permissions in O365 you should be able to search mailboxes just as you would on-prem. send all the cmdlets you are using to connect to exchange online so that we can see if you are using the correct ones to connect.
FOXActive Directory/Exchange EngineerCommented:
namerg,
Copy the below and paste it in notepad.  Save it to a folder of your liking Example c:\temp.   Name the text file o365connect.ps1  
Open powershell
Now change directories to c:\temp.  Once there type this     .\o365connect.ps1 and press Enter   You will be prompted for your o365 admin credentials, once you log in you will be able to perform your tasks.

$UserCredential = Get-Credential
Connect-MsolService -Credential $UserCredential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

namergSystems AdministratorAuthor Commented:
The is what i have done so far, i am able to connect and get data through CLI i will be able to insert the code within Solarwinds.

$UserCredential = Get-Credential
#Here i enter the following account SolarWinds-O365@domain.com
Connect-MsolService -Credential $UserCredential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

#I am stuck here

Get-PSSession | Remove-PSSession

Open in new window


I will try Fox's comment.
namergSystems AdministratorAuthor Commented:
Hmm, Fox what you posted is just session/connection creation. It does not take anywhere...
namergSystems AdministratorAuthor Commented:
And i have done what Jeremy posted...it is just session creation....
Jeremy WeisingerSenior Network Consultant / EngineerCommented:
You're almost there. Try this:

$UserCredential = Get-Credential
#Here i enter the following account SolarWinds-O365@domain.com
Connect-MsolService -Credential $UserCredential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session -DisableNameChecking

Open in new window

I changed the New-PSSession to what MS recommends and added the Import-PSSession. After that you should be able to run the Exchange cmdlets.

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
namergSystems AdministratorAuthor Commented:
Hmm, this line is not right...

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection$UserCredential -Authentication Basic -AllowRedirection

Open in new window

Jeremy WeisingerSenior Network Consultant / EngineerCommented:
Yeah, I noticed that it pasted funny. I edited it and it should be right now.

When you import the session you should see something like this:
ModuleType Version    Name                                ExportedCommands                                                                                                                                
---------- -------    ----                                ----------------                                                                                                                                
Script     1.0        tmp_mvnb1deq.rdx                    {Add-AvailabilityAddressSpace, Add-DistributionGroupMember, Add-MailboxFolderPermission, Add-MailboxLocation...}

Open in new window

You can then run the following to see what commands are available:
gcm -Module tmp_*

Open in new window

You should see all the Exchange cmdlets your user has access to.
namergSystems AdministratorAuthor Commented:
Thank You....and I was able to use Exchange Cmdlets. I think i am all set....
Jeremy WeisingerSenior Network Consultant / EngineerCommented:
Glad to help. :)
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
Powershell

From novice to tech pro — start learning today.