New Post has been published on o365info.com
New Post has been published on http://o365info.com/using-remote-powershell-to-manage_8596/
Using Remote PowerShell to manage Office 365 | Part 3/3
Expand All Headers Collapse All Headers
Part 3: Connect to Exchange Online by using Remote PowerShell
In The former part, we review the steps that we need to use for creating remote PowerShell to Office 365(Windows Azure Active Directory). Connecting to Exchange Online is a little bit different.
(If you prefer to get more âStraight forward version of: Connect to Exchange Online by using Remote PowerShell, you go use the link: Connecting to Exchange Online with Remote PowerShellâ PowerShell Nuggets )
We need to use more âcomplicatedâ PowerShell command for creating the remote session.
There is no need for download or install pre-requirement software, the Exchange Online cmdlets will be downloaded locally as part of the remote session
we can use the built-in PowerShell console ( no need to use the Microsoft Online Services Module for Windows PowerShell shortcut)
Using Copy & Paste option.
When we manually type PowerShell command, the command may include a syntax or spelling errors.
To avoid these scenarios, we can use the Copy/Paste option. For example: when a PowerShell command displayed in the article,
you can copy the command. Open the PowerShell console, right click on the console and chose the option: âPasteâ
Step 1: First time configurations
1 â Run as Administrator.
To change the PowerShell Execution Policy, we need to run the Windows PowerShell, by using the option: Run as administrator.
Right click on the PowerShell Console icon and chose the option: Run as administrator.
2- Change the default PowerShell Execution Policy
By default the PowerShell console will not allow us to run a script. We can enable script execution
by changing the default PowerShell Execution Policy to: Unrestricted. (The default mode is: Restricted).
To change the Execution policy open the PowerShell console and type the command:
Set-ExecutionPolicy Unrestricted
To execute PowerShell command, we use the âENTERâ key.
Step 2: Creating remote session to Exchange Online
For creating the remote connection we will need to use a set of three PowerShell commands. Each command perform different task and include variable that serve as a âcontainerâ for information such as: user credentials, URL etc..
The first command will cause the PowerShell console to display a âpop outâ Authentication window. After entering the required credential, the information will be âdeliveredâ to the ânextâ command.
The second command include the âTarget URLâ of the Exchange Online server that will accept our authentication request. The URL that we use function as a âfocal pointâ for all Office 365 customers. Based on the credentials that we provide (that include our domain name), the request will be redirected to the specific Exchange Online server that hosts our organization mailboxes.
The thread command will download the Exchange Online cmdlets to the local host (the desktop that we use for creating the remote PowerShell session.
copy the following âBlockâ of PowerShell commands and paste it on the PowerShell console:
PowerShell command Example
$cred = Get-Credential $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $cred -Authentication Basic âAllowRedirection Import-PSSession $Session
A pop out windows will appear. Type your credentials by using the UPN (user Principal name) format. For example: [email protected]
Note â the user name should have global administrator rights in Office 365.
After executing the command, the following message appears:
âWARNING: Your connection has been redirected to the following URI: âhttps://pod51013psh.outlook.com/PowerShell-LiveID?PSVersion=2.0 â WARNING: Your connection has been redirected to the following URI: https://dbxprd0312psh.outlook.com/PowerShell-LiveID?PSVersion=2.0 â
The URL that we use in the command: âhttps://ps.outlook.com/powershellâ serves as a âgeneral addressâ. Using the credential information that was provided in the former step, the remote session will be redirected to the specific Exchange Online server that host the mailbox of the user that create the session ( in our example the Exchange Online server address is: dbxprd0312psh.outlook.com)
In the last screen we can see the process of the import Exchange Online cmdlets
Congratulations! You are now connected to the Exchange Online.
Step 3: Verifying the remote connection
Q: How can we know if the remote session was successfully created?
A: To verify that we are connected, we type the name of Exchange Online cmdlets such as:Â Get-Mailbox
This command will display a list all the mailboxes that was created. In the screenshot you can see the list of Exchange Online mailboxes.
Step 4: Disconnecting the Remote PowerShell session
Remote PowerShell session to Exchange Online, have built in limitation:
The extinction of the remote PowerShell session -Â The maximum time for inactive (idle) remote PowerShell session is 15 minutes (this limitation is quite flexible because I manage to continue a PowerShell session that was idle for more than 15 minutes).
The amount of data that can be transferred in the remote PowerShell âChannelâ (throttling) â Exchange Online environment include a predefined restriction for the amount of data that can be transferred in one time. This limitation is implemented by using âthrottling Policyâ.
The number of concurrent remote PowerShell session -Â The maximum number of concurrent PowerShell session that we can use simultaneously is:Â three
The best practice is to disconnect a remote PowerShell session after we have finished using the required management tasks.
For disconnecting the remote PowerShell session use the following command:
Remove-PSSession $Session
The PowerShell indication for successful execution of commands is a little bit poor. The fact that we didnât receive an error message imply that the operation of âdisconnecting the remote PowerShell Sessionâ was successfully complete.
Q: How can know if the remote session was successfully disconnected?
A: To verify that the remote session was successfully disconnected you can try to type Exchange Online PowerShell cmdlets such as: Get-Mailbox
The following error will appear:
âThe term âget-mailboxâ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.â
This is actually a good sign (the error was expected). After disconnecting the PowerShell session, the PowerShell cmdlets for Exchange Online are no longer available.
Part 4: working with PowerShell cmdlets â basic introduction
In former articles we review the way for creating a remote PowerShell session to the Office 365 and Exchange Online.
In The last part we review the some basic PowerShell commands that will help us to get familiar with the cmdlets and the PowerShell command syntax.
Display list of the cmdlets
Office 365 and Exchange Online include a different set of cmdlets
To view a list of available Office 365 cmdlets, use following PowerShell command: get-command -module msOnline The name of the Office 365 cmdlets include the string âmsolâ (Microsoft Online). We can use this naming convention for displaying a list of Office 365 cmdlets, so additional option is to use the command: Get-command *msol*
You can view a reference of Office 365 cmdlets by using the following link: Windows PowerShell cmdlets for Office 365
2. Exchange Online cmdlets
Displaying a list of Exchange Online cmdlets are a little bit different form the way that we use for displaying the Office 365 cmdlets. When we create the remote PowerShell session to Exchange Online all of the cmdlets is dynamically downloaded to the local host.
In addition the Exchange Online cmdlets donât have a specific name convention like the Office 365 cmdlets. To view a list of available Exchange Online cmdlets, use following PowerShell command: Get-Command âModule tmp*
You can view a reference of Exchange Online cmdlets by using the following link: Reference to Available PowerShell Cmdlets in Exchange Online
Using the AutoComplete feature
The PowerShell console has a very useful feature named: AutoComplete as the name implies, we can use this feature for automatic compilation of PowerShell commands by typing the first letters of command name is using the TAB key.
The AutoComplete option enables us to work quickly and efficiently and in addition help us to avoid from the need to memorize the complete name of the PowerShell command (and avoid from typing syntax mistakes).
Example 1: AutoComplete with Remote PowerShell session to Exchange Online
We want to use the AutoComplete option for the command: Get-Mailbox
Type the command Get-M and hit the TAB key. You will see that the command is completed automatically to: Get-Mailbox
Example 2: AutoComplete with Remote PowerShell session to Office 365
We want to use the AutoComplete option for the command:Get-MsolUser
type the command Get-Msoland hit the TAB key. You will see that the command is completed automatically to: Get-MsolAccountSku
This is not the command that we wanted. The Office 365 cmdlets set include couple of cmdlets that begin with the name âGet-Msolâ. Using the TAB key, we can browse through all the cmdlets until we will reach to the required cmdlets. In our example we will need to hit the TAB key couple of time until the ârightâ command (Get-MsolUser) will be displayed.
Additional option that we could use for helping the PowerShell console to âunderstandâ better what we need is: Typing the command Get-Msolu, the addition of the âuâ letter will get us to the exact command that we need.
Using the PowerShell is based on a specific syntax that we need to use. One of the distinct advantage of the PowerShell environment is the good help reference for each of the PowerShell cmdlets.
To get information about specific cmdlets when can use the following command:
Get-Help
For example: to learn about the way we use the Get-MsolUser cmdlets type the following command Get-Help Get-MsolUser
If you need more information or examples about how to use the command, we can add the âDetailedâ option: Get-Help Get-MsolUser -Detailed
An additional option that we can use is displaying help information in HTML format.
We can use this nice trick by adding the option âOnlineâ.
For example: Get-help Get-mailbox âOnline
Note â in the current time the âOnline optionâ is available only for the Exchange Online environment.
In this 3 parts article series we learn about:
Why do we need to use PowerShell for managing the Office 365 cloud environment.
How to use remote PowerShell for managing Office 365 and Exchange Online
How to use PowerShell Basic introduction: using PowerShell cmdlets, using the AutoComplete feature and how to get information about the cmdlets that available for us.
I hope you enjoy reading and, May the force of PowerShell will be with you!
Now itâs Your Turn!
We really want to know what you think about the article