http://technet.microsoft.com/en-GB/library/jj984289(v=exchg.150).aspx
Using Powershell to connect to Office 365
Firstly, you need to create a connection to Office 365. You can do this by typing (or copying/pasting) the following into Powershell.
$UserCredential = Get-Credential
Once this is in the Powershell window, press Enter to execute the command.
Now you simply type in the username and password for an Administrator account in your Office 365 and click OK. You will probably see some warnings. Don’t worry, they are normal.You are now authenticated into Office 365. The last step is to connect up to Office 365 by using the following Powershell command:
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $session
Now you’ve gone to all the trouble of connecting to Powershell, let’s do something to prove that it works. Type the following into the Powershell window and press Enter:
Get-mailbox
Close session once completed: Remove-PSSession $Session