While trying Office 365 you might want to connect your to a remote Exchange Management Shell session instead of using the portal interface. Here’s how to proceed.
Start up a PowerShell session. The first thing we’re going to do next is store credentials in a variable for later usage:
$cred= Get-Credential
A popup will be displayed where you can enter your Office 365 admin credentials, e.g. myadminname@yourdomain.onmicrosoft.com.
Next, create a new remote PowerShell session using the following cmdlet:
$o365= New-PsSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $cred -AllowRedirection -Authentication Basic
Next, we can import the session. However, this might be confusing since you have no context; are you creating a mailbox local or in the Office 365 environment?
The cool thing is that with Import-Session you can specify a prefix. This prefix can be specified before the cmdlet noun so that PowerShell knows which session you want the cmdlet to run against. As you probably know, cmdlets are normally constructed using <verb>-<noun> syntax, but this should be <verb>-<session prefix><noun>. When the session prefix is omitted, PowerShell assumes the current session.
For example, let’s import our Office 365 session with a prefix of “o365”:
Import-PsSession $o365 –Prefix o365
Now, we can use that “o365” prefix before the noun. For example, to get a list of our Office 365 mailboxes, you’d use something like:
Get-o365Mailbox
Cool and simple, eh?
Don’t forget to close your online session afterwards using:
Remove-PsSession $o365
Have fun exploring Office 365 using PowerShell.
Pingback: Managing Office 365 with the one true shell | Thoughtsofanidlemind's Blog
Hey i get access denied , creating a new powershell session
LikeLike
Use proper credentials and make sure you set execution policy less strict, e.g. unrestricted
LikeLike
Pingback: HCW fails on intra-organization configuration | EighTwOne (821)
Pingback: Connecting to Office 365/Exchange | EighTwOne (821)