Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PowerShell Group Policy Reports

Posted on 2013-12-04
5
Medium Priority
?
443 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
1 Comment
 
LVL 25

Accepted Solution

by:
Coralon earned 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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 anti-spam), the admin…

824 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