{"id":1746,"date":"2014-03-27T00:01:00","date_gmt":"2014-03-27T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2014\/03\/27\/use-powershell-to-manage-exchange-online-in-office-365\/"},"modified":"2022-06-22T11:58:09","modified_gmt":"2022-06-22T18:58:09","slug":"use-powershell-to-manage-exchange-online-in-office-365","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/use-powershell-to-manage-exchange-online-in-office-365\/","title":{"rendered":"Use PowerShell to Manage Exchange Online in Office 365"},"content":{"rendered":"<p><strong>Summary<\/strong>: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell implicit\u00a0remoting to manage Exchange Online users.<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. This afternoon I am looking over my presentations for the <a href=\"http:\/\/powershell.org\/wp\/community-events\/summit\/powershell-summit-north-america\/\" target=\"_blank\" rel=\"noopener\">PowerShell Summit in Bellevue, Washington<\/a>. It will be April 28 \u2013 30, 2014, and I am making three presentations. So I need to prepare. There will be a bunch of really cool Windows PowerShell people speaking and attending. This is the stuff that geeks dream about. The Scripting Wife will also be there. Don\u2019t miss out.<\/p>\n<p><strong>\u00a0 \u00a0 \u00a0Note\u00a0<\/strong> This is the fourth in a series of Hey, Scripting Guy! Blog posts where I talk about using Windows PowerShell<br \/>\n\u00a0 \u00a0 \u00a0with Office\u00a0365.<\/p>\n<ul>\n<li>In <a href=\"https:\/\/devblogs.microsoft.com\/scripting\/getting-started-with-office-365-and-powershell\/\" target=\"_blank\" rel=\"noopener\">Getting Started with Office\u00a0365 and PowerShell<\/a>, I talked about setting up a demo environment and installing the prerequisite software to enable Windows PowerShell management of the demo environment. I also walked through the installation of the management module.<\/li>\n<li>In <a href=\"https:\/\/devblogs.microsoft.com\/scripting\/use-powershell-to-explore-office-365-installation\/\" target=\"_blank\" rel=\"noopener\">Use PowerShell to Explore Office\u00a0365 Installation<\/a>, I talked about using Windows PowerShell to explore the settings and the capabilities of my Office\u00a0365 tenant installation.<\/li>\n<li>In <a href=\"https:\/\/devblogs.microsoft.com\/scripting\/use-powershell-to-manage-office-365-users\/\" target=\"_blank\" rel=\"noopener\">Use PowerShell to Manage Office 365 Users<\/a>, I talk about finding unlicensed users, removing users, and modifying users.<\/li>\n<li>Today, I talk about using implicit remoting to work with Exchange Online users.<\/li>\n<\/ul>\n<h2>Make the connection<\/h2>\n<p>The first thing I need to do to use implicit remoting is create a new Windows PowerShell session to the remote location. The configuration name that I use is Microsoft.Exchange. The connection URI for me is <span>https:\/\/outlook.office365.com\/powershell<\/span>. I have read other blogs that state the connection URI is https:\/\/ps.outlook.com\/powershell. I am not sure if this is because it was an older version of Exchange in Office 365, or if it is simply the URI that they need to use.<\/p>\n<p>I experimented with a few things until I found it. I figured it would be easier and quicker than trying to find out why theirs was different. Anyway, I figured it out by looking at the URL in the Exchange admin center. This is shown here:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-3-27-14-01.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-3-27-14-01.png\" alt=\"Image of menu\" title=\"Image of menu\" \/><\/a><\/p>\n<p>I have my credentials stored in an XML file. (I talked about this in <a href=\"https:\/\/devblogs.microsoft.com\/scripting\/use-powershell-to-explore-office-365-installation\/\" target=\"_blank\" rel=\"noopener\">Use PowerShell to Explore Office 365 Installation<\/a>.) Therefore, I do not need to type my credentials.<\/p>\n<p>After I figure out the <strong>ConnectionURI<\/strong>, I use the following command to create a new Windows PowerShell remote session and to store the returned session in the <strong>$ex<\/strong> variable (this is a single-line command that is wrapped):<\/p>\n<p style=\"margin-left:30px\">\n  $ex = New-PSSession -ConfigurationName Microsoft.Exchange\n<\/p>\n<p style=\"margin-left:30px\">\n  -ConnectionUri https:\/\/outlook.office365.com\/powershell -Credential (Import-Clixml C:\\fso\\cred.xml)\n<\/p>\n<p style=\"margin-left:30px\">\n  -Authentication basic -AllowRedirection\n<\/p>\n<p>Next I import the session into my current Windows PowerShell shell. To do this, I use the **Import-PSSession **cmdlet as shown here:<\/p>\n<p style=\"margin-left:30px\">\n  Import-PSSession $ex\n<\/p>\n<p>I now use the <strong>Get-Module<\/strong> cmdlet to see what modules I have in my session:<\/p>\n<p style=\"margin-left:30px\">\n  Get-Module\n<\/p>\n<p>At this point, I pause and take a deep breath and look over my Windows PowerShell shell. It is shown in the image that follows:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-3-27-14-02.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-3-27-14-02.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>The next thing I like to do is to use <strong>Get-Command<\/strong> on the module. The module name is a temporary name, but by using tab expansion, it is really easy to get to. The following image shows some of the cmdlets:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-3-27-14-03.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-3-27-14-03.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>I can now use Windows PowerShell cmdlets that are very similar to the standard Exchange cmdlets I have used in the past. For example, I can get a Mailbox User report by using the <strong>Get-Mailbox<\/strong> cmdlet. The command and output are shown here:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-3-27-14-04.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-3-27-14-04.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>I can even access mailbox statistics for an individual mailbox or for all mailboxes. If I want the information for all mailboxes, I can simply pipe the results from <strong>Get-Mailbox<\/strong> to <strong>Get-MailboxStatistics<\/strong>. This command is shown here:<\/p>\n<p style=\"margin-left:30px\">\n  Get-Mailbox | Get-MailboxStatistics\n<\/p>\n<p>The command and output from the command are shown in the following image:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-3-27-14-05.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-3-27-14-05.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>I can find mailboxes where no one has signed in, as shown here:<\/p>\n<p style=\"margin-left:30px\">\n  Get-Mailbox | Get-MailboxStatistics | where {-not $_.lastlogontime}\n<\/p>\n<p>If I need a report of the number of active mailboxes, and the number of created accounts, I can use the <strong>Get-MailboxActivityReport<\/strong> cmdlet. It generates a number of helpful reports. For example, to produce a daily report, I use the command in the image that follows:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-3-27-14-06.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-3-27-14-06.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>That is all there is to using Windows PowerShell sessions and implicit remoting to connect to Exchange Online in Office 365. Office 365 Week will continue tomorrow when I will talk about more cool stuff.<\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\" rel=\"noopener\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\" rel=\"noopener\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\" rel=\"noopener\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\" rel=\"noopener\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><strong>Ed Wilson, Microsoft Scripting Guy<\/strong>\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell implicit\u00a0remoting to manage Exchange Online users. Microsoft Scripting Guy, Ed Wilson, is here. This afternoon I am looking over my presentations for the PowerShell Summit in Bellevue, Washington. It will be April 28 \u2013 30, 2014, and I am making three presentations. So I [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[27,49,291,57,3,4,45],"class_list":["post-1746","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-exchange","tag-office","tag-office-365","tag-remoting","tag-scripting-guy","tag-scripting-techniques","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell implicit\u00a0remoting to manage Exchange Online users. Microsoft Scripting Guy, Ed Wilson, is here. This afternoon I am looking over my presentations for the PowerShell Summit in Bellevue, Washington. It will be April 28 \u2013 30, 2014, and I am making three presentations. So I [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/1746","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=1746"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/1746\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=1746"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=1746"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=1746"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}