{"id":17641,"date":"2010-07-26T00:01:00","date_gmt":"2010-07-26T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2010\/07\/26\/parsing-an-auditpol-exe-report-with-windows-powershell-2-0\/"},"modified":"2010-07-26T00:01:00","modified_gmt":"2010-07-26T00:01:00","slug":"parsing-an-auditpol-exe-report-with-windows-powershell-2-0","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/parsing-an-auditpol-exe-report-with-windows-powershell-2-0\/","title":{"rendered":"Parsing an AuditPol.exe Report with Windows PowerShell 2.0"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p><img decoding=\"async\" height=\"34\" width=\"34\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" align=\"left\" alt=\"Hey, Scripting Guy! Question\" border=\"0\" title=\"Hey, Scripting Guy! Question\" \/> Hey, Scripting Guy! I have been using <a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/cc731451(WS.10).aspx\">AuditPol.exe<\/a> to verify the audit policy that is configured on our network. The problem is that the report that is generated has a lot of text, and it is not easy to see exactly what is being audited or not. Is it possible to use <a href=\"http:\/\/support.microsoft.com\/kb\/968929\">Windows PowerShell 2.0<\/a> to parse the report generated by AuditPol.exe to make the settings information easier to find?<\/p>\n<p>&#8212; PS<\/p>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" height=\"34\" width=\"34\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" align=\"left\" alt=\"Hey, Scripting Guy! Answer\" border=\"0\" title=\"Hey, Scripting Guy! Answer\" \/> Hello PS, <\/p>\n<p>Microsoft Scripting Guy Ed Wilson here. It is amazing how many people seem to want to talk to me each week. That is really cool. Teresa (my better half) will tell you that I love to talk, and if I get to talk about scripting&mdash;in particular, Windows PowerShell&mdash;that is all the better. On Thursday, July 29, I will be talking to the <a href=\"http:\/\/www.charlotte-sql.org\/meetings.html\">Charlotte SQL Users group<\/a>. They are a great bunch of people; this meeting was arranged back in March when I was in <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2010\/03\/13\/hey-scripting-guy-march-13-2010.aspx\">Charlotte for SQL Saturday<\/a>. It is always fun to talk to people who are interested in Windows PowerShell, and the cool thing is the way that Windows PowerShell and SQL Server have been brought together. <\/p>\n<p>In a meeting last week, we were talking about the way we had used <a href=\"http:\/\/office.microsoft.com\/en-us\/help\/microsoft-office-live-meeting-resource-center-HA010238900.aspx?CTT=1\">Live Meeting<\/a> during Tech&middot;Ed 2010 in New Orleans. Because I am not allowed to fly due to ear surgery, Craig and I used Live Meeting so that I could talk to people who were attending the conference. I then had the idea about trying to arrange to do the same thing for <a href=\"http:\/\/europe.msteched.com\/\">TechEd Europe 2010<\/a> that will be in Berlin. The only bad thing about Live Meeting is you do not actually get to go to the place where the meeting is held. Berlin is an awesome place. The following photo is one I took there while I was teaching a Windows PowerShell workshop a few years ago. <\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2063.hsg072610011_474EAC8B.jpg\"><img decoding=\"async\" height=\"449\" width=\"604\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1184.hsg072610011_thumb_10915187.jpg\" alt=\"Photo Ed took in Berlin\" border=\"0\" title=\"Photo Ed took in Berlin\" style=\"border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px\" \/><\/a> <\/p>\n<p>Tech&middot;Ed 2011 North American will be in Atlanta, Georgia, and even if I am not allowed to fly by then, I will be able to drive to that conference. By the way, there are also Tech&middot;Ed conferences in <a href=\"http:\/\/en.wikipedia.org\/wiki\/Australia\">Australia<\/a>, <a href=\"http:\/\/en.wikipedia.org\/wiki\/Japan\">Japan<\/a>, <a href=\"http:\/\/en.wikipedia.org\/wiki\/Brazil\">Brazil<\/a> and other places this year.<\/p>\n<p>When using the AuditPol.exe executable to generate an audit report, you need to run the program with administrator rights. I like to use the Windows PowerShell console to do this. In fact, I cannot remember the last time I opened an actual command prompt. Here is the AuditPol.exe command I used to generate an audit policy report, as well as the results generated from the report. You will notice that the Windows PowerShell command prompt is open to the C:\\Windows\\System32 folder. That is a feature of starting the Windows PowerShell console with administrator rights. <\/p>\n<p><span style=\"background-color: #f0f0f0\">PS C:\\Windows\\system32&gt; auditpol \/get \/category:*   <br \/>System audit policy    <br \/>Category\/Subcategory Setting    <br \/>System    <br \/>Security System Extension Success and Failure    <br \/>System Integrity No Auditing    <br \/>IPsec Driver No Auditing    <br \/>Other System Events No Auditing    <br \/>Security State Change No Auditing    <br \/>Logon\/Logoff    <br \/>Logon No Auditing    <br \/>Logoff No Auditing    <br \/>Account Lockout No Auditing    <br \/>IPsec Main Mode No Auditing    <br \/>IPsec Quick Mode No Auditing    <br \/>IPsec Extended Mode No Auditing    <br \/>Special Logon No Auditing    <br \/>Other Logon\/Logoff Events No Auditing    <br \/>Network Policy Server No Auditing    <br \/>Object Access    <br \/>File System No Auditing    <br \/>Registry No Auditing    <br \/>Kernel Object No Auditing    <br \/>SAM No Auditing    <br \/>Certification Services No Auditing    <br \/>Application Generated No Auditing    <br \/>Handle Manipulation No Auditing    <br \/>File Share No Auditing    <br \/>Filtering Platform Packet Drop No Auditing    <br \/>Filtering Platform Connection No Auditing    <br \/>Other Object Access Events No Auditing    <br \/>Detailed File Share No Auditing    <br \/>Privilege Use    <br \/>Sensitive Privilege Use No Auditing    <br \/>Non Sensitive Privilege Use No Auditing    <br \/>Other Privilege Use Events No Auditing    <br \/>Detailed Tracking    <br \/>Process Termination Success and Failure    <br \/>DPAPI Activity No Auditing    <br \/>RPC Events No Auditing    <br \/>Process Creation Success and Failure    <br \/>Policy Change    <br \/>Audit Policy Change No Auditing    <br \/>Authentication Policy Change No Auditing    <br \/>Authorization Policy Change No Auditing    <br \/>MPSSVC Rule-Level Policy Change No Auditing    <br \/>Filtering Platform Policy Change No Auditing    <br \/>Other Policy Change Events No Auditing    <br \/>Account Management    <br \/>User Account Management No Auditing    <br \/>Computer Account Management No Auditing    <br \/>Security Group Management No Auditing    <br \/>Distribution Group Management No Auditing    <br \/>Application Group Management No Auditing    <br \/>Other Account Management Events No Auditing    <br \/>DS Access    <br \/>Directory Service Changes No Auditing    <br \/>Directory Service Replication No Auditing    <br \/>Detailed Directory Service Replication No Auditing    <br \/>Directory Service Access No Auditing    <br \/>Account Logon    <br \/>Kerberos Service Ticket Operations No Auditing    <br \/>Other Account Logon Events No Auditing    <br \/>Kerberos Authentication Service No Auditing    <br \/>Credential Validation Success and Failure    <br \/>PS C:\\Windows\\system32&gt;<\/span><\/p>\n<p>To store the report in a text file, you can simply redirect the output to a file. This is shown here:<\/p>\n<p><span style=\"background-color: #f0f0f0\"><span style=\"color: #000000\">auditpol<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">\/get<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">\/category:*<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">c:\\fso\\audit.txt<\/span><\/span> <\/p>\n<p>The easy way to parse a text file is to use the <b>Select-String<\/b> cmdlet. If fact it is so easy, it is almost like no work at all. You mentioned you were interested in the things you are not auditing. Here is how to parse your audit.txt file and retrieve only the items you are not auditing:<\/p>\n<p><span style=\"background-color: #f0f0f0\">Select-String -Path C:\\fso\\audit.txt -Pattern &#8220;No Auditing&#8221;<\/span><\/p>\n<p>The output from the <b>Select-String<\/b> command is shown in the following image.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5126.hsg072610021_4BE4B745.jpg\"><img decoding=\"async\" height=\"452\" width=\"604\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6864.hsg072610021_thumb_3D3A0B60.jpg\" alt=\"Image of output from Select-String command\" border=\"0\" title=\"Image of output from Select-String command\" style=\"border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px\" \/><\/a> <\/p>\n<p>If you are not interested in the line number where the match occurs, you can filter it out. To filter out results from <b>Select-String<\/b>, it is important to realize that the command returns a <b>matchinfo<\/b> object. When you know the members of a <b>matchinfo<\/b> object, you can select the specific properties you are interested in receiving. The members of the <b>matchinfo<\/b> object are shown here:<\/p>\n<p><span style=\"background-color: #f0f0f0\">PS C:\\&gt; Select-String -Path C:\\fso\\audit.txt -Pattern &#8220;No Auditing&#8221; | get-member   <br \/>TypeName: Microsoft.PowerShell.Commands.MatchInfo    <br \/>Name MemberType Definition    <br \/>&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-    <br \/>Equals Method bool Equals(System.Object obj)    <br \/>GetHashCode Method int GetHashCode()    <br \/>GetType Method type GetType()    <br \/>RelativePath Method string RelativePath(string directory)    <br \/>ToString Method string ToString(), string ToString(string directory)    <br \/>Context Property Microsoft.PowerShell.Commands.MatchInfoContext Context {g&#8230;    <br \/>Filename Property System.String Filename {get;}    <br \/>IgnoreCase Property System.Boolean IgnoreCase {get;set;}    <br \/>Line Property System.String Line {get;set;}    <br \/>LineNumber Property System.Int32 LineNumber {get;set;}    <br \/>Matches Property System.Text.RegularExpressions.Match[] Matches {get;set;}    <br \/>Path Property System.String Path {get;set;}    <br \/>Pattern Property System.String Pattern {get;set;}    <br \/>PS C:\\&gt;<\/span><\/p>\n<p>By only choosing the <b>line<\/b> property, you can see the policy setting that is not being audited. This is shown here:<\/p>\n<p><span style=\"background-color: #f0f0f0\">PS C:\\&gt; Select-String -Path C:\\fso\\audit.txt -Pattern &#8220;No Auditing&#8221; | Select-Object l   <br \/>ine    <br \/>Line    <br \/>&#8212;-    <br \/>System Integrity No Auditing    <br \/>IPsec Driver No Auditing    <br \/>Other System Events No Auditing    <br \/>Security State Change No Auditing    <br \/>Logon No Auditing    <br \/>Logoff No Auditing    <br \/>Account Lockout No Auditing    <br \/>IPsec Main Mode No Auditing    <br \/>IPsec Quick Mode No Auditing    <br \/>IPsec Extended Mode No Auditing    <br \/>Special Logon No Auditing    <br \/>Other Logon\/Logoff Events No Auditing    <br \/>Network Policy Server No Auditing    <br \/>File System No Auditing    <br \/>Registry No Auditing    <br \/>Kernel Object No Auditing    <br \/>SAM No Auditing    <br \/>Certification Services No Auditing    <br \/>Application Generated No Auditing    <br \/>Handle Manipulation No Auditing    <br \/>File Share No Auditing    <br \/>Filtering Platform Packet Drop No Auditing    <br \/>Filtering Platform Connection No Auditing    <br \/>Other Object Access Events No Auditing    <br \/>Detailed File Share No Auditing    <br \/>Sensitive Privilege Use No Auditing    <br \/>Non Sensitive Privilege Use No Auditing    <br \/>Other Privilege Use Events No Auditing    <br \/>DPAPI Activity No Auditing    <br \/>RPC Events No Auditing    <br \/>Audit Policy Change No Auditing    <br \/>Authentication Policy Change No Auditing    <br \/>Authorization Policy Change No Auditing    <br \/>MPSSVC Rule-Level Policy Change No Auditing    <br \/>Filtering Platform Policy Change No Auditing    <br \/>Other Policy Change Events No Auditing    <br \/>User Account Management No Auditing    <br \/>Computer Account Management No Auditing    <br \/>Security Group Management No Auditing    <br \/>Distribution Group Management No Auditing    <br \/>Application Group Management No Auditing    <br \/>Other Account Management Events No Auditing    <br \/>Directory Service Changes No Auditing    <br \/>Directory Service Replication No Auditing    <br \/>Detailed Directory Service Replication No Auditing    <br \/>Directory Service Access No Auditing    <br \/>Kerberos Service Ticket Operations No Auditing    <br \/>Other Account Logon Events No Auditing    <br \/>Kerberos Authentication Service No Auditing    <br \/>PS C:\\&gt;<\/span><\/p>\n<p>On the other hand, if you wish to see only the items that are audited, you can modify the pattern to return lines that contain the string &ldquo;Success and Failure&rdquo; as shown here:<\/p>\n<p><span style=\"background-color: #f0f0f0\">PS C:\\&gt; Select-String -Path C:\\fso\\audit.txt -Pattern &#8220;Success and Failure&#8221; | Select-   <br \/>Object line    <br \/>Line    <br \/>&#8212;-    <br \/>Security System Extension Success and Failure    <br \/>Process Termination Success and Failure    <br \/>Process Creation Success and Failure    <br \/>Credential Validation Success and Failure    <br \/>PS C:\\&gt;<\/span><\/p>\n<p>You can get much more sophisticated in the way you parse text files by including more complex regular expression patterns. Check out the <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/tags\/windows+powershell\/regular+expressions\/\">Hey, Scripting Guy! archives for a good introduction to using regular expressions<\/a> with Windows PowerShell. <\/p>\n<p>&nbsp;<\/p>\n<p>PS, that is all there is to using Windows PowerShell to work with strings. String Week will continue tomorrow when we will talk about splitting strings into an array. <\/p>\n<p>We would love for you to follow us on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\">Twitter<\/a> or <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\">Facebook<\/a>. If you have any questions, send email to us at <a href=\"mailto:scripter@microsoft.com\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/social.technet.microsoft.com\/Forums\/en\/ITCG\/threads\/\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p>&nbsp;<\/p>\n<p><b>Ed Wilson and Craig Liebendorfer, Scripting Guys<\/b><\/p>\n<p><b>&nbsp;<\/b><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Hey, Scripting Guy! I have been using AuditPol.exe to verify the audit policy that is configured on our network. The problem is that the report that is generated has a lot of text, and it is not easy to see exactly what is being audited or not. Is it possible to use Windows PowerShell [&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":[3,4,21,45],"class_list":["post-17641","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-scripting-guy","tag-scripting-techniques","tag-string-manipulation","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>&nbsp; Hey, Scripting Guy! I have been using AuditPol.exe to verify the audit policy that is configured on our network. The problem is that the report that is generated has a lot of text, and it is not easy to see exactly what is being audited or not. Is it possible to use Windows PowerShell [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/17641","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=17641"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/17641\/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=17641"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=17641"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=17641"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}