Solved

PowerShell Group Policy Reports

Posted on 2013-12-04
5
401 Views
1 Endorsement
Last Modified: 2014-10-06
Hello,

I'm attempting to get a good report in Excel for over 300 group policies.  I'd also like to get these in on one excel sheet so that I can sort, and view to find duplicate settings that I can combine. I'm finding this isn't as easy as I thought it was going to be. I tried exporting a report using get-gporeport but the export of the gporeport.xml doesn't open up good at all in excel, plus I don't want to open up each report manually and copy the contents over.

I also looked at SDM, but there is no budget for that so I have to look at scripts to do this.

I'm extremely new to scripting and still don't quite understand the scripting language but have tried the following to export some of the contents in the XML file.

Script so far
$xml = [xml](get-content 'C:\temp\gpo\gpreport.xml')
$xml.GPO | foreach {$_.Name + ":" + $_.CreatedTime + ":" + $_.User.Enabled + ":" + $_.User.ExtensionData.Name}

Results
IT EXPLORER:2008-05-13T18:44:40:true:Internet Explorer Maintenance Registry

Am I doing this correctly? What I want is to export the name, owner, created date, and the settings name, and settings for each of the policies, disabled or not, linked or not, etc...

Thanks
Lito
1
Comment
Question by:litog
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 25

Accepted Solution

by:
Coralon earned 500 total points
ID: 39719029
You are on the right track from what I can see (I'm not at work, so I can't generate my own GPO report to see the XML.  Can you load a sample of the XML data?)  I need to know what it looks like, but you can make some optimizations.

[xml]$xml = new-object -typename xml
$xml.load('C:\temp\gpo\gpreport.xml')

$xml.gpo | foreach {
     ($_.Name, $_.CreatedTime, $_.User.Enabled, $_.User.ExtensionData.Name) -join ':'
}

Open in new window


1. Using the $xml.load is substantially faster than using get-content.  The more policies and settings you are dealing with, the more you will notice it.  (I've seen it listed as 7 times faster).
2. The -join is faster and easier then using regular concatenation.  Without the XML file, I can't be 100% sure of the needed syntax, but digging through something similar I have done before... I did this:
$xml.Folders | foreach {($_.Folder.AppFolder) -join ':'}

Open in new window


The XML source was similar to this:
<Folders>
     <Folder AppFolder='Folder1'> 
     </Folder>
     <Folder AppFolder='Folder2'> 
     </Folder>
</Folders>

Open in new window


The key is that you are working with XML elements. The AppFolder attribute outputs as a string, so you can use -join with it.  

Coralon
1

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Know what services you can and cannot, should and should not combine on your server.
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question