Solved

PowerShell Group Policy Reports

Posted on 2013-12-04
5
373 Views
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
0
Comment
Question by:litog
5 Comments
 
LVL 23

Accepted Solution

by:
Coralon earned 500 total points
Comment Utility
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
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now