How To Connect To Office 365 Using Windows Powershell
How to Connect Function 365 Commutation Online Services to PowerShell
The default method for managing Microsoft Office 365 with all included applications is past using a web browser and connecting to the web interface of Office 365 Admin Eye and Exchange Admin Eye. This standard method has an intuitive graphical interface, simply sometimes the capabilities of the graphical user interface are not plenty. For example, when yous need to perform similar actions with tens or hundreds of user accounts, information technology is better to use the CLI (command line interface) rather than the GUI (graphical user interface). Moreover, some actions that tin can be washed with Exchange Online cmdlets are not available in the Admin Heart.
Microsoft provides PowerShell to manage the products in the command line interface. Many administrators have the habit of managing Microsoft Exchange Server via PowerShell. However, standard commands of the Substitution PowerShell module that work in the local environment with a standalone example of Microsoft Substitution Server installed on a concrete server or a virtual machine cannot be used with Exchange 365 running in the cloud. This is because standard PowerShell commands cannot connect to cloud services such every bit Azure and Office 365 backup, including Exchange Online. For this reason, you will need to install special PowerShell modules that allow you to connect to Office 365. The details of this process are covered in today'due south blog post that explains multiple methods of how to connect to Commutation Online PowerShell and consists of the following parts:
- Requirements
- The Working Principle
- Manual Configuration
- Automated Configuration
- The Culling Method
NAKIVO Backup & Replication offers improved backup capabilities by adding Microsoft Office 365 backup to its feature set. Outset the Complimentary Trial of our product, discover how NAKIVO Backup & Replication works in your environment, and receive an Amazon eGift card for your feedback.
Requirements
At that place are some requirements that must exist met to connect to Exchange Online PowerShell.
- You should use PowerShell on Windows vii SP1, or newer desktop Windows versions and Windows Server 2008 R2 SP1, or newer server Windows versions. Be enlightened that you lot need to install .Internet Framework 4.v or subsequently in addition to installing an updated version of Windows Management Framework 3.0, 4.0, or five.1.
- An cyberspace connection is required. TCP port lxxx must exist opened to connect from your local machine to the destination host.
- Admission to Exchange Online PowerShell must be enabled for the electric current user (past default such access is enabled for administrators).
Y'all tin manually enable admission to connect to Substitution Online PowerShell for the particular user with the control:
Fix-User -Identity user@domain.com -RemotePowerShellEnabled $true
Working Principle
You tin can connect to Exchange Online PowerShell, but this procedure is more complicated than using PowerShell for managing a local Commutation Server. Yet, you can employ the built-in PowerShell panel to manage remote cloud infrastructures. In this instance, the console is called remote PowerShell or PowerShell Remoting. The procedure of initiating a remote PowerShell session for Office 365 and Exchange Online is slightly dissimilar. You should download and install special components earlier you lot can open up a remote Office 365 session. Fortunately, the cmdlets required to initiate a remote Exchange Online PowerShell are downloaded automatically when you lot create a remote PowerShell session. Different sets of PowerShell cmdlets are used to manage Microsoft Part 365 and Microsoft Exchange Online.
The main reasoning behind connecting to Microsoft Exchange Online in PowerShell entails the following:
- Creating a remote session to Exchange Online in PowerShell opened on your local motorcar.
- Providing connexion settings, passing authentication.
- Importing PowerShell cmdlets that are needed to manage Commutation Online remotely.
In today'south blog post, we volition run PowerShell cmdlets on Windows 10.
Manual Configuration
Allow'south review the manual method first, to understand the configuration principle better.
- Open Windows PowerShell. You tin can do this with at least two methods.
- Click Start, type cmd, right click the Command Prompt detail and select Run as Administrator in the context menu.
- Go to Start > Windows PowerShell. Right click Windows PowerShell, and striking Run as Administrator to make sure that you can run PowerShell commands without restrictions.
- Enable running scripts (information technology is better to run this command in the beginning of preparing PowerShell to manage Commutation Online and Office 365), otherwise yous will get the error in futurity when running the Import-PSSession command:
Import-PSSession : Files cannot be loaded since running scripts has been disabled on this organization. Provide a valid certificate with which to sign the files. - In order to execute scripts, the execution policy must exist set up to RemoteSigned.
Set-ExecutionPolicy RemoteSigned - Press Y to confirm changing the policy if prompted. You can also use the Fix-ExecutionPolicy Unrestricted control to use the Unrestricted policy. By default, the execution policy mode is Restricted.
- Run the control in PowerShell to go credentials and enter your administrator login/password in the popup window to admission Commutation Online. The user must have global authoritative permissions in Office 365.
$Credential=Get-Credential The entered credentials will exist saved in the variable and used in the next command as $Credential. - You have to create a remote PowerShell session with the New-PSSession cmdlet and running the following control:
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Credential -Hallmark Basic -AllowRedirectionNotice that in this command, the target URL of the Exchange Online server running in the cloud that must accept the request is prepare. After running the control, Microsoft Office 365 deject servers volition provide you access to the advisable Commutation Online virtual server associated with your account.
- Exchange Online PowerShell cmdlets must be imported to the electric current session with the command:
Import-PSSession $Session
- You lot tin can see the progress bar while receiving the commands.
- After successfully running the command, you will run into the following message. Note: If you use the MFA for your business relationship, the standard cmdlets explained above volition not work. If you lot want to connect Commutation Online in PowerShell using MFA, run the following command:
Connect-EXOPSSession -UserPrincipalName YOUR_UPN
Where YOUR_UPN (user principle proper name) is the name of the Office 365 account you lot are using.Y'all may demand to install Microsoft's Exchange Online Remote PowerShell Module. Be aware that when using this module, the session ends subsequently one hour, which may be inconvenient for running long scripts. Consider using Trusted IP addresses (i.e. the IP addresses of your organisation) to bypass MFA when connecting from the network of your visitor to Substitution Online PowerShell.
MFA (Multi-Factor-Hallmark) is the advanced method of hallmark that adds a second layer of security. After entering a countersign, the confirmation lawmaking is sent to the user's cell phone and the user must enter the confirmation code to verify the account to go access to Office 365 deject services.
- Once you have connected to Office 365 and Exchange Online, you can manage your Office 365 cloud surroundings. Let'due south verify that we have connected to Exchange Online correctly and list the mailboxes of users, for instance.
Get-Mailbox Yous can list all cmdlets bachelor for Exchange Online PowerShell with the following command:
Get-Command -Module tmp*
The names of Commutation Online PowerShell cmdlets are not converted. - When you end your work with Exchange 365, disconnect the session. This is the recommended do.
Remove-PSSession $SessionUnfortunately, no messages are displayed later executing this command. You can check whether the session is asunder by running the Get-MailBox command. If the session is asunder, you volition get the mistake explaining that yous cannot run Exchange Online cmdlets subsequently disconnecting.
Why should you disconnect the session? Well, simply considering the number of active concurrent sessions that can be opened simultaneously is limited to iii. If y'all open three Exchange Online PowerShell sessions at in one case and don't disconnect whatsoever of them when not in employ, you volition need to wait until ane of these sessions expires before you tin can connect to Exchange Online PowerShell again from a new PowerShell console.
Automatic Configuration
Now that you know the principle of how to connect to Exchange Online PowerShell manually, yous can employ the automated method. The reward of this method is the lower number of commands you should enter.
- Download the script from the Microsoft'southward spider web site. The name of the script file is ConnectExchangeOnlinePowerShell.ps1 in this case.
- Get to the directory where the script is located; in our example, the script is saved to C:\temp_win\.
- Earlier running the script, edit the script execution policy (similarly to what is shown in the first method), otherwise y'all will become the fault:
The file C:\temp_win\ConnectExchangeOnlinePowerShell.ps1 is not digitally signed. You cannot run this script on the current system.
Y'all can employ the Bypass execution policy to avoid this upshot:
Prepare-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass - Type Y to confirm the execution policy modify.
- Afterward that, y'all can run the script. If you don't employ MFA, run the script without additional arguments:
.\ConnectExchangeOnlinePowerShell.ps1
If MFA (Multi-Factor Authentication) is used in your Function 365 surroundings, try the command:
.\ConnectExchangeOnlinePowerShell.ps1 -MFA - Now that you have successfully connected to Commutation Online, you can manage your user accounts, their mailboxes, etc. For example, you can listing the mailboxes of your users:
Become-Mailbox
This script can be used to schedule and automate tasks. For example, you tin can connect to Substitution Online without entering credentials in the interactive window equally shown above. You tin can enter your login and password in the control line as command options when executing the script:
./ConnectExchangeOnlinePowerShell.ps1 -UserName admin@your_domain.com -Password your_password
Continue in listen that entering passwords as plainly text in the control line may exist not secure. - When yous finish to piece of work with Substitution Online in PowerShell, don't forget to stop the session:
./ConnectExchangeOnlinePowerShell.ps1 -Disconnect
Alternative Method
Permit's consider one more method that tin be used to connect to Exchange Online PowerShell. This method can be considered as a modification of the offset method.
i. Create a new contour for PowerShell with the function:
New-item -type file -force $contour
2. Edit the profile configuration file in the text editor to add together the office titled Connect-EXOnline:
notepad $contour
iii. Add the following content to the PowerShell profile configuration file and change username@domain.com to your account name, then save the text file.
Part Connect-EXOnline
{
$credentials = Become-Credential -Credential username@domain.com
Write-Output "Getting the Exchange Online cmdlets"
$Session = New-PSSession -ConnectionUri https://outlook.office365.com/powershell-liveid/ `
-ConfigurationName Microsoft.Substitution -Credential $credentials `
-Authentication Basic -AllowRedirection
Import-PSSession $Session
}
4. Shut the electric current PowerShell window and open a new PowerShell window as Ambassador. Run the command to connect to Exchange Online PowerShell:
Connect-ExOnline
Enter your password in the popup window.
5. When you lot have finished working with Exchange Online PowerShell, end the session with the command:
Get-PSSession | Remove-PSSession
Conclusion
Commutation Online PowerShell is a nice culling to the Substitution Admin Heart web interface. With Role 365 PowerShell and Commutation Online PowerShell, you can perform majority operations and actions with multiple objects by using a single command or script. Today'due south blog post has covered how to connect to Exchange Online PowerShell past using three methods, one of which is automated. The working principle of each method is like and consists of iii chief steps: create a remote PowerShell session, authenticate, and import Substitution Online PowerShell cmdlets.
An important recommendation is that you disconnect the remote PowerShell session when you cease working with Substitution Online PowerShell to avoid a state of affairs when all sessions are busy and opening a new remote Commutation Online PowerShell session is not possible. Having Exchange Server in the cloud is a reliable solution, merely even in this case, it is recommended that yous make a backup of your Substitution server to protect your data against incidental deletion and other disasters. Read the blog post about the three-2-1 fill-in rule and other blog posts about data protection options that NAKIVO Fill-in & Replication has to offer to learn more.
Source: https://www.nakivo.com/blog/how-to-connect-office-365-exchange-online-powershell/
Posted by: hancockhandep84.blogspot.com
0 Response to "How To Connect To Office 365 Using Windows Powershell"
Post a Comment