Start up a PowerShell session. The first thing we’re going to do next is store credentials in a variable for later usage:
A popup will be displayed where you can enter your Office 365 admin credentials, e.g. firstname.lastname@example.org.
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:
Cool and simple, eh?
Don’t forget to close your online session afterwards using:
Have fun exploring Office 365 using PowerShell.