{"id":1202,"date":"2018-02-21T15:22:09","date_gmt":"2018-02-21T13:22:09","guid":{"rendered":"https:\/\/msb365.abstergo.ch\/?p=1202"},"modified":"2023-06-23T13:16:39","modified_gmt":"2023-06-23T11:16:39","slug":"10-useful-powershell-cmdlets-exchange","status":"publish","type":"post","link":"https:\/\/www.msb365.blog\/?p=1202","title":{"rendered":"10 Useful PowerShell cmdlets for Exchange"},"content":{"rendered":"<p>On the Ignite 2017 <a href=\"https:\/\/myignite.microsoft.com\/speaker\/218175?source=speakerdetail\" target=\"_blank\" rel=\"noopener\"><strong>Steve Goodman<\/strong><\/a>\u00a0held a very good session about 10 useful PowerShell commands, which are important to know as an Exchange admin. I am going to present you these 10 commands here, with a little explanation for each of it.<\/p>\n<p>Some of the commands are more known that others, but I hope you will enjoy it and it will help you to operate your environment more smoothly\u2026<\/p>\n<p>\u00a0<\/p>\n<hr \/>\n<h3>The first command: <span style=\"color: #333399;\"><strong>GET-HELP<\/strong><\/span><\/h3>\n<p>\u00a0<\/p>\n<p>Ok, every one of us knows the get-help command. It is a simple one but still, very useful!<\/p>\n<p>How does this command works?<\/p>\n<p>Let\u2019s take the following example:<\/p>\n<p>You need to set up a new transport rule on your Exchange server. But you are not sure how to do that. So one way to be sure how to use the command right, is to get some examples. You can simply do this with the following command:<\/p>\n<pre class=\"\">Get-Help New-TransportRule \u2013Examples<\/pre>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-full wp-image-1205\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/1-3.png\" alt=\"\" width=\"1140\" height=\"743\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/1-3.png 1140w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/1-3-300x196.png 300w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/1-3-768x501.png 768w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/1-3-1024x667.png 1024w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/1-3-600x391.png 600w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/1-3-780x508.png 780w\" sizes=\"(max-width: 1140px) 100vw, 1140px\" \/><\/p>\n<p>As we can see in the picture above, PowerShell shows us some examples for the New-TransportRule command.<\/p>\n<p>But what if this is not enough? What if we need more information about the command? Like, what is needed and what is optional? And how to show this in a nice, comfortable view?<\/p>\n<p>For this, we can use the parameter <em>-Online<\/em>:<\/p>\n<pre class=\"\">Get-Help New-TransportRule \u2013Online<\/pre>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-1206\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/2-1.png\" alt=\"\" width=\"593\" height=\"228\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/2-1.png 593w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/2-1-300x115.png 300w\" sizes=\"(max-width: 593px) 100vw, 593px\" \/><\/p>\n<p>\u00a0<\/p>\n<p>And here\u2019s the result:<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-1207\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/2-1-1.png\" alt=\"\" width=\"1412\" height=\"839\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/2-1-1.png 1412w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/2-1-1-300x178.png 300w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/2-1-1-768x456.png 768w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/2-1-1-1024x608.png 1024w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/2-1-1-600x357.png 600w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/2-1-1-780x463.png 780w\" sizes=\"(max-width: 1412px) 100vw, 1412px\" \/><\/p>\n<p>If you have an internet connection on the server you are running the Exchange management shell, it will open up a web browser and point directly to the corresponding Microsoft Technet article. This saves you time for searching and you\u00b4ll have all info you need about the New-TransportRule cmdlet.<\/p>\n<p>\u00a0<\/p>\n<hr \/>\n<h3>So let\u2019s get to our second command: <strong><span style=\"color: #333399;\">GET-CONTENT<\/span><\/strong><\/h3>\n<p>The Get-Content cmdlet allows you to examine your log files. You can also watch them in real-time!<\/p>\n<p>As an example: Let\u2019s have a look into the IIS log files. Our task is to check if some requests are coming through, or not. So I choose the current log file with the Get-Content command like:<\/p>\n<pre class=\"\">Get-Content (file) -Tail 1 -Wait<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1208\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/3-1.png\" alt=\"\" width=\"1041\" height=\"595\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/3-1.png 1041w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/3-1-300x171.png 300w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/3-1-768x439.png 768w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/3-1-1024x585.png 1024w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/3-1-600x343.png 600w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/3-1-780x446.png 780w\" sizes=\"(max-width: 1041px) 100vw, 1041px\" \/><\/p>\n<p>The <em>\u2013Wait<\/em>\u00a0parameter does the real-time thing. Every time new content is added to the file, the Get-Content cmdlet will ad-hoc show this content in the console. The optional part <em>-Tail 1<\/em> is for showing only the last line (<em>1<\/em>) of the log file. Now, we see what is going on on the IIS\u00a0in real-time.<\/p>\n<p>If we store the Get-Content call into a variable, we\u2019re also able to peak at the entries line by line. The content of the file then is stored as a string array through which you can navigate now by index number:<\/p>\n<pre class=\"\">$File = Get-Content (file)\r\n$File[1]<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1209\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/4-1.png\" alt=\"\" width=\"1023\" height=\"160\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/4-1.png 1023w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/4-1-300x47.png 300w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/4-1-768x120.png 768w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/4-1-600x94.png 600w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/4-1-780x122.png 780w\" sizes=\"(max-width: 1023px) 100vw, 1023px\" \/><\/p>\n<p>Get-Content is a fantastic troubleshooting tool you can use.<\/p>\n<p>\u00a0<\/p>\n<hr \/>\n<h3>The next command I would like to present is <span style=\"color: #333399;\"><strong>SELECT-OBJECT<\/strong><\/span><\/h3>\n<p>\u00a0<\/p>\n<p>The Select-Object cmdlet is one of the core commands we need for working with PowerShell. Many engineers are using the command format list after the pipe and then start searching line by line for the needed info and then select it for further commands.<\/p>\n<p>With the select-object command you can directly pick what you need and nothing else!<\/p>\n<p>When you get data from one command, the Get-Mailbox as an example, just send it through the pipe. That means you can send it to the next command. The next command is <em>select<\/em>, (aka\u00a0<em>select-object<\/em>) followed by the properties (comma separated) which we want to see. Those of you who already have some PowerShell experience may be familiar with it.<\/p>\n<p>Here\u2019s an example how to use the select-object command\u2026<\/p>\n<p>We run:<\/p>\n<pre class=\"\">Get-Mailbox | Select DisplayName, SamAccountName, UserPrincipalName, PrimarySMTPAddress<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1210\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/5-1.png\" alt=\"\" width=\"1140\" height=\"743\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/5-1.png 1140w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/5-1-300x196.png 300w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/5-1-768x501.png 768w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/5-1-1024x667.png 1024w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/5-1-600x391.png 600w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/5-1-780x508.png 780w\" sizes=\"(max-width: 1140px) 100vw, 1140px\" \/><\/p>\n<p>So, we get all the info we need in form of a little report and thereby get only the information we have requested.<\/p>\n<p>We can also use it in other ways as well.<\/p>\n<p>We can use it to get a report of mailbox sizes of mailboxes in a specific database. We are going to get the display name and something that is not shown by default: I want to see the total item size.<\/p>\n<pre class=\"\">Get-MailboxStatistics -Database (DM) | Select DisplayName, TotalItemSize<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1211\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/6-1.png\" alt=\"\" width=\"1140\" height=\"743\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/6-1.png 1140w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/6-1-300x196.png 300w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/6-1-768x501.png 768w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/6-1-1024x667.png 1024w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/6-1-600x391.png 600w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/6-1-780x508.png 780w\" sizes=\"(max-width: 1140px) 100vw, 1140px\" \/><\/p>\n<p>As you can see, we\u2019ve built a very simple report over mailbox sizes in our Exchange environment.<\/p>\n<p>\u00a0<\/p>\n<hr \/>\n<h3>The next PowerShell cmdlet we write about is : <span style=\"color: #333399;\"><strong>Start-Transcript<\/strong><\/span><\/h3>\n<p>This cmdlet is perfect if you want to keep track on what you are doing, e.g when you are making changes to your environment.<\/p>\n<p>If you are using Microsoft Exchange 2010, 2013 or 2016, you may have to actually capture what changes you have made, but that does not capture all the commands you typed in. Especially not the ones against Exchange. Perhaps you\u2019re getting content from files to edit them first, before making changes.<\/p>\n<p>You may be trying to create a script and you want to capture as you go along. Maybe doing the tests for your scripts by running parts of it in the shell first and then copy and paste it into notepad, or ISE.<\/p>\n<p>Start-Transcript will allow us to record all that into a text file.<\/p>\n<p>So let\u2019s have a look at an example\u2026<\/p>\n<p>First, we need to start the transcript with:<\/p>\n<pre class=\"\">Start-Transcript<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1212\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/7.png\" alt=\"\" width=\"1140\" height=\"743\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/7.png 1140w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/7-300x196.png 300w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/7-768x501.png 768w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/7-1024x667.png 1024w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/7-600x391.png 600w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/7-780x508.png 780w\" sizes=\"(max-width: 1140px) 100vw, 1140px\" \/><\/p>\n<p>Do all sorts of damage, but it\u2019s OK because you had a change request approved\u2026 \ud83d\ude09<\/p>\n<p>And, as you can see in the print screen, the path is provided, where the log file is saved to. Just run the following to stop recording.<\/p>\n<pre class=\"\">Stop-Transcript<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1213\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/8.png\" alt=\"\" width=\"1140\" height=\"743\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/8.png 1140w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/8-300x196.png 300w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/8-768x501.png 768w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/8-1024x667.png 1024w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/8-600x391.png 600w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/8-780x508.png 780w\" sizes=\"(max-width: 1140px) 100vw, 1140px\" \/><\/p>\n<p>So if we need to check which changes we have done, we simply navigate to the log file and check our changes:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1217\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/9-3.png\" alt=\"\" width=\"1275\" height=\"665\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/9-3.png 1275w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/9-3-300x156.png 300w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/9-3-768x401.png 768w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/9-3-1024x534.png 1024w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/9-3-600x313.png 600w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/9-3-780x407.png 780w\" sizes=\"(max-width: 1275px) 100vw, 1275px\" \/><\/p>\n<p>As you can see, it\u2019s so much easier to check for mistakes, or wrong configurations with this, than to search through everything\u2026<\/p>\n<p>\u00a0<\/p>\n<hr \/>\n<h3>Now let\u2019s continue with the <strong><span style=\"color: #333399;\">Test-NetConnection<\/span><\/strong> command<\/h3>\n<p>\u00a0<\/p>\n<p>With this command, we are for example able to check the connection to O365 in hybrid environments.<\/p>\n<p>You can either run the tests through this cmdlet manually to check if the port is open from Exchange service to the Office 365 service. But you don\u2019t need to do commands to prove the port is open. You can use it on a script base and then have actions executed, dependent on the result. You could, if you want to, run it across multiple services. So, it\u2019s really easy to do.<\/p>\n<p>Let\u2019s see an example\u2026<\/p>\n<p>We run the following command:<\/p>\n<pre class=\"\">Test-NetConnection outlook.office365.com -Port 25<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1218\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/10.png\" alt=\"\" width=\"1140\" height=\"743\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/10.png 1140w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/10-300x196.png 300w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/10-768x501.png 768w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/10-1024x667.png 1024w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/10-600x391.png 600w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/10-780x508.png 780w\" sizes=\"(max-width: 1140px) 100vw, 1140px\" \/><\/p>\n<p>We can also check the mail flow of the Exchange server to O365.<\/p>\n<p>Simply hit this into the shell:<\/p>\n<pre class=\"\">Test-NetConnection outlook.office365.com -Traceroute<\/pre>\n<p>We can use this instead of the trace route (tracert)\u2026<\/p>\n<p>As you can see in the picture below, it can take some moments\u2026<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1219\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/11.png\" alt=\"\" width=\"1140\" height=\"743\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/11.png 1140w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/11-300x196.png 300w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/11-768x501.png 768w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/11-1024x667.png 1024w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/11-600x391.png 600w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/11-780x508.png 780w\" sizes=\"(max-width: 1140px) 100vw, 1140px\" \/><\/p>\n<p>When the process is done, we get the following result:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1220\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/12.png\" alt=\"\" width=\"1140\" height=\"743\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/12.png 1140w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/12-300x196.png 300w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/12-768x501.png 768w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/12-1024x667.png 1024w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/12-600x391.png 600w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/12-780x508.png 780w\" sizes=\"(max-width: 1140px) 100vw, 1140px\" \/><\/p>\n<p>With the output of this command, I can create some reports if needed. We can combine it with commands like <em>select(-object)<\/em> to use the data to create our own reports. We can put it into a word document or\u00a0examine the words you see later in a different way. It\u2019s a nice way of helping us, first of all, to do tests quickly. We can create scripts, which allow us to automate the tests against our environment on a regular basis and we can get information that we can bring into reports to find out significantly more information very quickly.<\/p>\n<p>There are more great commands that go with this.<\/p>\n<p>\u00a0<\/p>\n<hr \/>\n<h3>I hope you didn\u2019t got bored yet, because here\u2019s the next cmdlet: <strong><span style=\"color: #333399;\">Export-CliXML<\/span><\/strong><\/h3>\n<p>\u00a0<\/p>\n<p>If we want to make sure we are having a solid record of everything we have done, this is our favorite command.<\/p>\n<p>We are able to capture the entire output, even the stuff we don\u2019t see, in its native PowerShell format into an xml file. We can take that file and use it on the same machine, put it on our notebook, use it to generate our reports and create scripts based on the information in the xml file.<\/p>\n<p>It\u2019s the output of the command, that we can use again and again to see what it looks like at that point in time.<\/p>\n<p>Here, I\u2019m going to run this command and I\u2019m going to show you, how I can move the info between two computers.<\/p>\n<p>Let\u2019s run the following command:<\/p>\n<pre class=\"\">Get-Mailbox -ResultSize Unlimited | Export-CliXML .\\Mailboxes.XML<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1221\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/13.png\" alt=\"\" width=\"1140\" height=\"743\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/13.png 1140w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/13-300x196.png 300w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/13-768x501.png 768w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/13-1024x667.png 1024w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/13-600x391.png 600w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/13-780x508.png 780w\" sizes=\"(max-width: 1140px) 100vw, 1140px\" \/><\/p>\n<p>So, we have exported the CliXML.<\/p>\n<p>Now, we\u2019re going to move it to a different client:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1222\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/14.png\" alt=\"\" width=\"623\" height=\"260\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/14.png 623w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/14-300x125.png 300w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/14-600x250.png 600w\" sizes=\"(max-width: 623px) 100vw, 623px\" \/><\/p>\n<p>Then we jump to another server. This machine doesn\u2019t have any Exchange management tools installed.<\/p>\n<p>We are just opening with nothing else loaded then native PowerShell console! Now, we can use the following command to import the file:<\/p>\n<pre class=\"\">Import-CliXML .\\Mailboxes.XML<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1223\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/15.png\" alt=\"\" width=\"1282\" height=\"547\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/15.png 1282w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/15-300x128.png 300w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/15-768x328.png 768w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/15-1024x437.png 1024w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/15-600x256.png 600w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/15-780x333.png 780w\" sizes=\"(max-width: 1282px) 100vw, 1282px\" \/><\/p>\n<p>And as we see, it shows the exact content of what we got in the mailbox.<\/p>\n<p>Let\u2019s move on to the next command\u2026<\/p>\n<p>\u00a0<\/p>\n<hr \/>\n<h3>This time let\u2019s talk about the <span style=\"color: #333399;\"><strong>Out-GridView<\/strong><\/span> cmdlet<\/h3>\n<p>If you don\u2019t like to search your information across the command line output, we have the opportunity to use the grid view.<\/p>\n<p>So, what does <em>Out-GridView<\/em> do? The\u00a0<em>Out-GridView<\/em>\u00a0cmdlet shows the output of a command in a separate window. This window has a user-friendly interface, where the output of command is displayed in a nice, sorted and ordered way. You can see here, that suddenly there\u2019s a user interface showing the information, we\u2019d usually see in the shell.<\/p>\n<p>It is very simply to use it, lets do it with the following example:<\/p>\n<pre class=\"\">Get-Mailbox | Out-GridView<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1224\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/16.png\" alt=\"\" width=\"1256\" height=\"753\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/16.png 1256w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/16-300x180.png 300w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/16-768x460.png 768w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/16-1024x614.png 1024w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/16-600x360.png 600w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/16-780x468.png 780w\" sizes=\"(max-width: 1256px) 100vw, 1256px\" \/><\/p>\n<p>The output of the <em>Get-Mailbox<\/em> cmdlet is piped to\u00a0<em>Out-GridView. Out-GridView <\/em>then presents that output in form of a table inside a grid view control.<\/p>\n<p>You can now add criteria for filtering, sort by columns and, by right clicking a column header, even add and\/or remove columns.<\/p>\n<p>If you pipe the output to the <em>select<\/em>\u00a0cmdlet between the originating cmdlet and the <em>Out-GridView<\/em> cmdlet, you can also define all available properties of the piped object that will be available as columns.<\/p>\n<p>For example, if you also want to have the primary smtp address of the mailboxes shown in your grid view, just add that property to the <em>select<\/em> command, as follows:<\/p>\n<pre class=\"\">Get-Mailbox | select Name,Alias,PrimarySMTPAddress,ServerName,ProhibitSendQuota | Out-GridView<\/pre>\n<p>The result would look like in the picture below.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1245\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/out-gridview_1-1.png\" alt=\"\" width=\"673\" height=\"270\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/out-gridview_1-1.png 673w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/out-gridview_1-1-300x120.png 300w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/out-gridview_1-1-600x241.png 600w\" sizes=\"(max-width: 673px) 100vw, 673px\" \/><\/p>\n<p>Here are some simple examples, which commands work with <em>Out-GridView<\/em>:<\/p>\n<pre class=\"\">Get-Mailbox | Out-GridView\r\n\r\nGet-ExchangeServer | Out-GridView\r\n\r\nGet-User | Out-GridView<\/pre>\n<p>Basically, you can send any PowerShell object to <em>Out-GridView.<\/em><\/p>\n<h5>The Passthru parameter<\/h5>\n<p>A very cool parameter this cmdlet also has, is the<em> -PassThru<\/em>\u00a0parameter.<\/p>\n<p>If you execute <em>Out-GridView<\/em> with this parameter, you\u2019ll first notice that\u00a0<em>OK<\/em> and <em>Cancel<\/em> buttons are added to the grid view window. Objects, which you select in the grid view control, will now be passed into the pipe again, after you click the \u201cOK\u201d button.\u00a0 Now, you can use these objects for further processing by just piping from <em>Out-GridView, <\/em>again, to your next command. See following example.<\/p>\n<pre class=\"\">Get-Process | Out-GridView -PassThru | Stop-Process<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1248\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/outgridview_passthru_1.png\" alt=\"\" width=\"505\" height=\"483\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/outgridview_passthru_1.png 505w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/outgridview_passthru_1-300x287.png 300w\" sizes=\"(max-width: 505px) 100vw, 505px\" \/><\/p>\n<p>Here, I first selected the two Adobe Reader processes. After I hit the <em>OK<\/em> button, the objects of the selected processes are piped to the <em>Stop-Process<\/em> cmdlet and therefore will be stopped right away.<\/p>\n<p>You can use this in combination with Exchange cmdlets, too. For example to execute any action on multiple mailboxes which you\u2019ve selected in the grid view.<\/p>\n<p>Soon we are coming to the end of this article. \u00a0Only three left, but from my point of view, they are very important and highly recommended for scripting tasks.<\/p>\n<p>\u00a0<\/p>\n<hr \/>\n<h3>The next I want to present you is: <span style=\"color: #333399;\"><strong>foreach<\/strong><\/span>.<\/h3>\n<p>\u00a0<\/p>\n<p>When you use the <em>Get-Content<\/em> command and store the information into an array, then went through it line by line by line manually, what it allows you to do.<\/p>\n<p>We can stick line-by-line through the input file or something like <em>Get-Mailbox<\/em>, and then we can perform the same check or test or action against each of those lines one-by-one.<\/p>\n<p>It\u2019s the foundation for the reporting scripts. We can go off of another command, against the output of the first command.<\/p>\n<p>Let\u2019s see a very simple example to grab the output from G<em>et-Mailbox<\/em>\u2026<\/p>\n<p>We run the following commands:<\/p>\n<pre class=\"\">$Mailboxes = get-mailbox\r\nForeach ($Mailbox in $Mailboxes){get-user -Identity $Mialbox.userPrincipalName}<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1225\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/17.png\" alt=\"\" width=\"980\" height=\"293\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/17.png 980w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/17-300x90.png 300w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/17-768x230.png 768w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/17-600x179.png 600w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/17-780x233.png 780w\" sizes=\"(max-width: 980px) 100vw, 980px\" \/><\/p>\n<p>As you can see, it is very simple to use. We need something to put in for each. We have a list of mail boxes here. Then we pass that through and every single mailbox will have G<em>et-User<\/em> run against it. It\u2019s at one time, and this could be a whole long list of commands in a script, and often it will not be just one line.<\/p>\n<p>\u00a0<\/p>\n<hr \/>\n<h3>The second to last command I am writing about is: <strong><span style=\"color: #333399;\">where<\/span><\/strong><\/h3>\n<p>\u00a0<\/p>\n<p>We can get the output and filter it. You are looking for something very specific. We could use it to find everybody who has a certain last name in the entire list of mailboxes in our organization or everybody with a job title of executive, and just grab that info.<\/p>\n<p>What it does, what it relies on, get mailbox running, and get all the information to the PowerShell session, and if you have an environment with 20\u2019000 or 70\u2019000 people, that could take 15 minutes or longer to run.<\/p>\n<p>In some circumstances, you should look at the command itself, and you can see if there\u2019s a filter perimeter. That will allow you to trim back and filter out the data, very easily.<\/p>\n<p>Here, where the filter command is not supported on many commands, or full of the properties it doesn\u2019t support, it only supports the simple ones, and we can use it against any PowerShell command in Exchange and elsewhere to filter and find the specific information.<\/p>\n<p>\u00a0<\/p>\n<p>It\u2019s very useful for gaining quick insight into our environment to find out the scale of problems perhaps.<\/p>\n<p>Here an example: I need to check and find out people who have an email address policy disabled. This that I know here I have to make a manual update.<\/p>\n<p>For that, we run the following command:<\/p>\n<p>\u00a0<\/p>\n<pre class=\"\">Get-Mailbox | Where {$_.EmailAddressPolicyEnabled -eq $False}<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1226\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/18.png\" alt=\"\" width=\"1140\" height=\"743\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/18.png 1140w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/18-300x196.png 300w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/18-768x501.png 768w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/18-1024x667.png 1024w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/18-600x391.png 600w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/18-780x508.png 780w\" sizes=\"(max-width: 1140px) 100vw, 1140px\" \/><\/p>\n<p>\u00a0<\/p>\n<p>As you can see, we could use it to filter the output very easily from any of the Exchange PowerShell commands. It\u2019s very easy to use.<\/p>\n<p>\u00a0<\/p>\n<p>Here some examples about how to use this commands:<\/p>\n<p>\u00a0<\/p>\n<pre class=\"\">Get-Mailbox | Where {$_.EmailAddressPolicyEnabled -eq $False}<\/pre>\n<pre class=\"\">Get-Mailbox -ResultSize Unlimited |where-object {$_.haspicture -eq $false} |select-object name,UserPrincipalName,haspicture | Export-Csv C:\\TMP\\UserWithoutPic.csv<\/pre>\n<p>\u00a0<\/p>\n<p>So here the last one for this article\u2026<\/p>\n<p>\u00a0<\/p>\n<hr \/>\n<h3>Let\u2019s talk about <span style=\"color: #333399;\"><strong>Export-CSV<\/strong><\/span>:<\/h3>\n<p>\u00a0<\/p>\n<p>This command is the foundation of all reports that has to be generated for a customer on a regular basis.<\/p>\n<p>So if we want to create reports that shows sharing the organization and permissions and top ten mailbox sizes, this is the one, without a doubt!!<\/p>\n<p>This command is being used hundreds of thousands of times in the scripts and commands. Without it, we couldn\u2019t present information back to the business to help them make decisions about things like migrations or easily get infotmation into the documentation I correct.<\/p>\n<p>We could, for example, do a report on a web services directories to see what needs to be changed.<\/p>\n<p>We could\u00a0 go up to the server, and we will use the select, again, one of the foundation top 10 commands, and we will pipe that to export csv. Here we will use no type in the information to grab:<\/p>\n<pre class=\"\">Get-WebServicesVirtualDirectory | Select Server, InternalURI, ExternalURI | Export-Csv -NoTypeInformation .\\EWSVirtualDirectories.Csv<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1227\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/19.png\" alt=\"\" width=\"1228\" height=\"581\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/19.png 1228w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/19-300x142.png 300w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/19-768x363.png 768w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/19-1024x484.png 1024w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/19-600x284.png 600w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/02\/19-780x369.png 780w\" sizes=\"(max-width: 1228px) 100vw, 1228px\" \/><\/p>\n<p>\u00a0<\/p>\n<p>So, his are 10 of the most useful PowerShell cmdlets. As I wrote in the beginning, my motivation to write this article is, because of the Ignite session of <a href=\"https:\/\/myignite.microsoft.com\/speaker\/218175?source=speakerdetail\" target=\"_blank\" rel=\"noopener\">Steve Goodman<\/a>. If you would like to watch his session, I highly can recommend you this <a href=\"https:\/\/www.youtube.com\/watch?time_continue=569&v=mPvWWHk1SAM\" target=\"_blank\" rel=\"noopener\"><strong>LINK<\/strong><\/a>.\u00a0 It will point you to his Ignite session.<\/p>\n<p>Or you can just watch it here in our blog:<\/p>\n<p><iframe  id=\"_ytid_24613\"  width=\"480\" height=\"270\"  data-origwidth=\"480\" data-origheight=\"270\" src=\"https:\/\/www.youtube.com\/embed\/mPvWWHk1SAM?enablejsapi=1&autoplay=0&cc_load_policy=0&cc_lang_pref=&iv_load_policy=1&loop=0&rel=1&fs=1&playsinline=0&autohide=2&theme=dark&color=red&controls=1&disablekb=0&\" class=\"__youtube_prefs__  epyt-is-override  no-lazyload\" title=\"YouTube player\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><\/p>\n<hr \/>\n<p style=\"text-align: center;\"><span style=\"color: #33cccc;\"><strong>At this point, I want to say thank you personally to Steve for supporting me with this article!<\/strong><\/span><\/p>\n<p>\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>On the Ignite 2017 Steve Goodman\u00a0held a very good session about 10 useful PowerShell commands, which are important to know as an Exchange admin. I am going to present you these 10 commands here, with a little explanation for each of it. Some of the commands are more known that others, but I hope you [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3019,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[1923,2,3],"tags":[],"class_list":["post-1202","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-microsoft-365","category-exchange","category-powershell"],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/www.msb365.blog\/index.php?rest_route=\/wp\/v2\/posts\/1202","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.msb365.blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.msb365.blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1202"}],"version-history":[{"count":27,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=\/wp\/v2\/posts\/1202\/revisions"}],"predecessor-version":[{"id":5216,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=\/wp\/v2\/posts\/1202\/revisions\/5216"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=\/wp\/v2\/media\/3019"}],"wp:attachment":[{"href":"https:\/\/www.msb365.blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1202"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1202"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1202"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}