{"id":11371,"date":"2012-01-25T00:01:00","date_gmt":"2012-01-25T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2012\/01\/25\/use-powershell-to-audit-changes-made-to-exchange-server-2010\/"},"modified":"2012-01-25T00:01:00","modified_gmt":"2012-01-25T00:01:00","slug":"use-powershell-to-audit-changes-made-to-exchange-server-2010","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/use-powershell-to-audit-changes-made-to-exchange-server-2010\/","title":{"rendered":"Use PowerShell to Audit Changes Made to Exchange Server 2010"},"content":{"rendered":"<p><b>Summary<\/b>: Learn how to use a new Exchange Server 2010 cmdlet to audit via Windows PowerShell changes made to the server.<\/p>\n<p><span><span><span><span><span><span><span><span><img decoding=\"async\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\" \/><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>&nbsp;Hey, Scripting Guy! I am not sure this is a scripting question, but I need help, and you seem to like to help people. In fact, if you cannot help me, I might be looking for a new job. Here is the deal. We are running Microsoft Exchange Server 2010 and we are running Service Pack&nbsp;1. We are currently evaluating Service Pack&nbsp;2; but frankly, after the trouble we had upgrading to Service Pack&nbsp;1, it might be a while. The problem is that there are several Exchange administrators in our company, and recently we have been having all sorts of Exchange Server problems. I have checked the Application Logs and the Security Logs to try to see who has been making the bad changes to our server, but I do not see anything that can help me chase it down. Please don&rsquo;t tell me I have to enable something, because I would love to prove it is not me who has been messing up.<\/p>\n<p>&mdash;BV<\/p>\n<p><span><span><span><span><span><span><span><span><img decoding=\"async\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\" \/><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>Hello BV,<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. Back when I was a consultant, I was called in to help a company determine who had been embezzling money by manipulating their accounting database. I was able to identify the changes; unfortunately, they were all made via the Administrator account. BV, if your Exchange administrators use their own user accounts to do their work, and they are not using a generic logon account, it is very possible that changes made to your Exchange Server&nbsp;2010 are logged. This is because Exchange Server&nbsp;2010 has a feature called <a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/dd335052.aspx\" target=\"_blank\">Administrator Audit Logging<\/a>. The good news is that new installations of Exchange Server&nbsp;2010 Service Pack&nbsp;1 enable this logging by default.<\/p>\n<p>To make it easier to work remotely, I wrote about the <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2012\/01\/23\/learn-how-to-use-powershell-to-run-exchange-server-commands-remotely.aspx\" target=\"_blank\"><strong>New-ExchangeSession<\/strong> function<\/a> on Monday and the <b><a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2012\/01\/24\/gain-remote-access-to-the-get-excommand-exchange-server-command.aspx\" target=\"_blank\">Get-ExCommand <\/a><\/b><a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2012\/01\/24\/gain-remote-access-to-the-get-excommand-exchange-server-command.aspx\" target=\"_blank\">function<\/a> and on Tuesday in the Hey, Scripting Guy! Blog. I uploaded the two functions to the <a href=\"http:\/\/gallery.technet.microsoft.com\/scriptcenter\/Exchange-Server-2010-9d5e13be\" target=\"_blank\">Exchange Server 2010 Helper Function library<\/a> in the Scripting Guys Repository. You can find them here:<\/p>\n<ul>\n<li><a href=\"http:\/\/gallery.technet.microsoft.com\/scriptcenter\/Create-a-new-implicit-5fdafe45\" target=\"_blank\">New-ExchangeSession<\/a><\/li>\n<li><a href=\"http:\/\/gallery.technet.microsoft.com\/scriptcenter\/Remote-Get-ExCommand-5f1384ae\" target=\"_blank\">Get-ExCommand <\/a><\/li>\n<\/ul>\n<p>In keeping with my Windows PowerShell best practices, this function library incorporates two new aliases for the two functions. The first alias is <b>NXS<\/b> for the <b>New-ExchangeSession<\/b> function, and the second alias is <b>GCX<\/b> for the <b>Get-ExchangeCommand<\/b>. The first thing to do is to dot source the two functions into my current environment. Here is an example of how to do that (note there is a space between the period and the path to the function library. This command brings both functions and both aliases into the current environment.<\/p>\n<p style=\"padding-left: 30px\">. E:\\data\\ScriptingGuys\\2012\\HSG_1_23_12\\ExchangeHelperFunctions.ps1<\/p>\n<p>The commands to import the helper function library, use the aliases to create a new implicit remoting session to the server running Exchange Server&nbsp;2010, and then use the alias to retrieve the Exchange commands appears in the image that follows.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8524.HSG-1-25-12-01.jpg\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8524.HSG-1-25-12-01.jpg\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>After establishing an implicit remoting session to the remote server, the Windows PowerShell console is ready to use to manage the server. One of the cool features of Exchange Server&nbsp;2010 is the <a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/dd335052.aspx\" target=\"_blank\">Administrator Audit Logging<i> <\/i>feature.<\/a> This feature logs when a user or an administrator makes a change to the Exchange organization. This permits the ability to trace back changes to a specific user for auditing purposes. In addition, the detailed logging provides a history of changes to the organization, which are useful from a regulatory compliance perspective or as a troubleshooting tool.<\/p>\n<p>By default, Microsoft Exchange Server 2010 Service Pack 1 enables audit logging on new installations. To determine the status of audit logging, use the <b>Get-AdminAuditLogConfig<\/b> command. The use of this command and the associated 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\/8182.HSG-1-25-12-02.jpg\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8182.HSG-1-25-12-02.jpg\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>In a large network, it might be preferable to specify a specific domain controller from which to retrieve the administrator audit logging configuration. To do this, use the <i>DomainController <\/i>parameter. On my network, I can use the host name or the fully qualified domain name (fqdn). These two commands are shown here:<\/p>\n<p style=\"padding-left: 30px\">Get-AdminAuditLogConfig -DomainController dc1<\/p>\n<p style=\"padding-left: 30px\">Get-AdminAuditLogConfig -DomainController dc1.iammred.net<\/p>\n<p>Prior to Service Pack 1, when enabled, the Administrator Audit Logging feature sent emails to a specific audit-log mailbox configured via the <b>Set-AdminAuditLogConfig <\/b>cmdlet, and it was examined via an email client. After Exchange Server&nbsp;2010 Service Pack 1, the audit entries reside in a <a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/bb201680.aspx\" target=\"_blank\">hidden mailbox<\/a>, and the <b>Search-AdminAuditLog <\/b>cmdlet retrieves the entries. The mailbox appears in the <i>Users <\/i>container in the Active Directory Users and Computers tool, and it is possible to obtain statistics about this mailbox by using the <b>Get-MailboxStatistics <\/b>cmdlet. This command is shown here:<\/p>\n<p style=\"padding-left: 30px\">Get-MailboxStatistics &#8220;SystemMailbox{e0dc1c29-89c3-4034-b678-e6c29d823ed9}&#8221;<\/p>\n<p>Exchange Server&nbsp;2010 Service Pack&nbsp;1 has a cmdlet called <b>Search-AdminAuditLog. <\/b>When run without any parameters, the <b>Search-AdminAuditLog <\/b>cmdlet returns all records. By default, the retention period is 90 days (on a fresh Exchange Server&nbsp;2010 Service Pack 1 installation). Configure the retention period by using the <b>Set-AdminAuditLog <\/b>cmdlet.<\/p>\n<p>When you make a change to the administrator audit logging, keep in mind that changes rely on Active Directory replication to take place; and therefore, they could take up to an hour to replicate through the domain. Also, keep in mind that changes to auditing apply to the entire Exchange organization&mdash;there is no granularity. The following command sets the retention period to 120 days.<\/p>\n<p style=\"padding-left: 30px\">Set-AdminAuditLogConfig -AdminAuditLogAgeLimit 120<\/p>\n<p>To retrieve all of the admin audit logs, use the <b>Search-AdminAuditLog <\/b>cmdlet without any parameters, as shown here:<\/p>\n<p style=\"padding-left: 30px\">Search-AdminAuditLog<\/p>\n<p>The command to retrieve all of the admin audit logs and the output that is associated with that command is shown in the image that follows.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8130.HSG-1-25-12-03.jpg\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8130.HSG-1-25-12-03.jpg\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>It is certainly possible to pipe the results from the <b>Search-AdminAuditLog <\/b>cmdlet to a <b>Where-Object <\/b>cmdlet, but it is better to use the parameters when possible. For example, to see only changes from the <i>administrator <\/i>user account, use the U<i>serIDs <\/i>parameter as shown here:<\/p>\n<p style=\"padding-left: 30px\">Search-AdminAuditLog -UserIds administrator<\/p>\n<p>To see audit log entries that occur prior to a specific date, use the <i>EndDate <\/i>parameter. The following commands retrieve audit entries from events created by the <i>administrator <\/i>user account that occurred prior to January 18, 2012.<\/p>\n<p style=\"padding-left: 30px\">Search-AdminAuditLog -UserIds administrator -EndDate 1\/18\/12<\/p>\n<p style=\"padding-left: 30px\">Search-AdminAuditLog -UserIds administrator -EndDate &#8220;january 18, 2012&#8221;<\/p>\n<p>To review only the audit entries that are generated by a specific cmdlet use the <i>Cmdlets <\/i>parameter. The following example only retrieves audit entries that are generated by the <b>Enable-Mailbox <\/b>cmdlet.<\/p>\n<p style=\"padding-left: 30px\">Search-AdminAuditLog -Cmdlets Enable-Mailbox<\/p>\n<p>The <i>Cmdlets <\/i>parameter accepts an array of cmdlet names. To find audit events that are generated by either the <b>Enable-Mailbox <\/b>or the <b>Set-Mailbox <\/b>cmdlet use the command shown here:<\/p>\n<p style=\"padding-left: 30px\">Search-AdminAuditLog -Cmdlets Enable-Mailbox, Set-Mailbox<\/p>\n<p>One really powerful feature of the admin auditing framework is to use the <b>New-AdminAuditLogSearch <\/b>cmdlet. In addition to searching the admin audit logs, this cmdlet also emails the report when it is completed. The email includes an XML attachment that contains the results from the search. The <i>StartDate <\/i>and the <i>EndDate <\/i>parameters are mandatory parameters that limit the size of the returned report. Reports are limited to 10 megabytes in size, and they take up to 15 minutes to arrive in the Inbox. The following command is a single logical line command (no line continuation characters) that creates a new report of all <b>Enable-Mailbox <\/b>commands used between 1\/1\/2012 and 1\/18\/2012. The command emails the report to edwilson@iammred.net.<\/p>\n<p style=\"padding-left: 30px\">New-AdminAuditLogSearch -cmdlets enable-Mailbox -StatusMailRecipients edwilson@iammred.net -StartDate 1\/1\/2012 -EndDate 1\/18\/2012<\/p>\n<p>The command and the output associated with the command are shown in the image that follows.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2287.HSG-1-25-12-04.jpg\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2287.HSG-1-25-12-04.jpg\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>The image that follows is the email with the search results from the previous query.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2480.HSG-1-25-12-05.jpg\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2480.HSG-1-25-12-05.jpg\" alt=\"Image of email message\" title=\"Image of email message\" \/><\/a><\/p>\n<p>The XML attachment is shown in the image that follows.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1307.HSG-1-25-12-06.jpg\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1307.HSG-1-25-12-06.jpg\" alt=\"Image of XML script\" title=\"Image of XML script\" \/><\/a><\/p>\n<p>Refer to the <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2009\/11\/16\/hey-scripting-guy-november-16-2009.aspx\" target=\"_blank\">Hey, Scripting Guy! Is There an Easier Way to Work with XML Files<\/a><i> <\/i>blog for information about using Windows PowerShell to work with XML files.<\/p>\n<p>BV, that is all there is to using the administrator audit log cmdlets. Join me tomorrow for more Windows PowerShell cool stuff.&nbsp;<\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><strong>Ed Wilson, Microsoft Scripting Guy<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Learn how to use a new Exchange Server 2010 cmdlet to audit via Windows PowerShell changes made to the server. &nbsp;Hey, Scripting Guy! I am not sure this is a scripting question, but I need help, and you seem to like to help people. In fact, if you cannot help me, I might be [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[28,180,3,45],"class_list":["post-11371","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-messaging-and-communication","tag-microsoft-exchange-2010","tag-scripting-guy","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Learn how to use a new Exchange Server 2010 cmdlet to audit via Windows PowerShell changes made to the server. &nbsp;Hey, Scripting Guy! I am not sure this is a scripting question, but I need help, and you seem to like to help people. In fact, if you cannot help me, I might be [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/11371","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\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=11371"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/11371\/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=11371"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=11371"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=11371"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}