New-GPOReport.ps1

# Get-GPO.ps1
# Writen By Brandon Shell aka(BSonPosh)
# Gets GPO or GPOs according to Parameters
# Parameters
#  -Path:    Location for Reports
#  -GPOName: Name of the GPO
#  -GUID:    Unique GUID for GPO
# Switches
#  -All:     Reports for All GPO's
#  -Verbose: Enables Verbose Logging
Param(
    $Path = $(throw '$Path is required. Please provide location to save Report(s)'),
    $GPOName,
    $GUID,
    [switch]$all,
    [switch]$Verbose)

if($verbose){$verbosepreference = "continue"}else{$erroractionpreference = "SilentlyContinue"}
if(!($GPOName -or $GUID -or $All)){Write-Host "Please supply GPOName or -All to Import" -fore Yellow}
. "$pwd\Set-GPEnvironment.ps1"

if($GUID)
{
    Write-Verbose " - Getting GPO Object for $GUID"
    $gpo = $gpmDomain.SearchGPOs($gpm.CreateSearchCriteria()) | Where-Object{$_.ID -eq "{$GUID}"}
    $reportfile = "$path\$($GPO.DisplayName).xml"
    Write-Verbose " + Generating Report and saving to $reportfile"
    $gpo.GenerateReportToFile($gpmconstants.ReportXML,$reportfile) | out-Null
    if(test-Path $reportfile)
    {
        Write-Host "   - Report Created Successfully for [$($GPO.DisplayName)]." -fore Green
    }
    else
    {
        Write-Host "   - Report Created Failed for [$($GPO.DisplayName)]!" -fore Red  
    }
}

if($GPOName)
{
    Write-Verbose " - Getting GPO Object for $GPOName"
    $gpo = $gpmDomain.SearchGPOs($gpm.CreateSearchCriteria()) | Where-Object{$_.DisplayName -eq $GPOName}
    if($gpo.count){Write-Host "Found [$($gpo.count)] for Name [$GPOName]. Please use GUID.";return}
    $reportfile = "$path\$($GPO.DisplayName).xml"
    Write-Verbose " + Generating Report and saving to $reportfile"
    $gpo.GenerateReportToFile($gpmconstants.ReportXML,$reportfile) | out-Null
    if(test-Path $reportfile)
    {
        Write-Host "   - Report Created Successfully for [$($GPO.DisplayName)]." -fore Green
    }
    else
    {
        Write-Host "   - Report Created Failed for [$($GPO.DisplayName)]!" -fore Red  
    }
}

if($all)
{
    foreach($gpo in ($gpmDomain.SearchGPOs($gpm.CreateSearchCriteria())))
    {
        Write-Verbose " + Getting Report for $($gpo.DisplayName)"
        $reportfile = "$path\$($GPO.DisplayName).xml"
        Write-Verbose "   - Generating Report and saving to $reportfile"
        $gpo.GenerateReportToFile($gpmconstants.ReportXML,$reportfile) | out-Null
        if(test-Path $reportfile)
        {
            Write-Host "   - Report Created Successfully for [$($GPO.DisplayName)]." -fore Green
        }
        else
        {
            Write-Host "   - Report Created Failed for [$($GPO.DisplayName)]!" -fore Red
        }
    }
}
Write-Host

Attachments:
 New-GPOReport.txt- New-GPOReport.ps1 script referenced in Chapter 11. Please change file extension from .txt to .ps1
 

Be a hero! Report a problem with this web page here

Event Calendar

Find out where and when Jeremy will be speaking next.

November 2008
SMTWTFS
1
2345678
9101112131415
16171819202122
23242526272829
30
Mon, Nov 10 - Thu, Nov 13
Windows Connections -- Vegas
It's WinConnections time! All sorts of great speeches this time. GP Troubleshooting, My Pre-Con, App-V 101. Will you be there?
www.winconnections.com
Mon, Nov 17 - Tue, Nov 18
Two-Day Intensive Group Policy Essentials Workshop (taught by Jeremy Moskowitz (Lead Instructor) - GPanswers.com / Moskowitz, Inc. )
 Final class of 2008.
This is a Two-Day Intensive Group Policy Essentials Workshop in Atlanta, GA !
Wed, Nov 19 - Thu, Nov 20
Two-Day "Group Policy 2.0" Catch-Up Workshop (taught by Jeremy Moskowitz (Lead Instructor) - GPanswers.com / Moskowitz, Inc. )
 Final class of 2008.
This is a Two-Day "Group Policy 2.0" Catch-Up Workshop in Atlanta, GA !
Fri, Nov 21 - Fri, Nov 21
One-Day Advanced Group Policy Workshop (XP/Vista Focused) (taught by Jeremy Moskowitz (Lead Instructor) - GPanswers.com / Moskowitz, Inc. )
 Final class of 2008.
This is a One-Day Advanced Group Policy Workshop (XP/Vista Focused) in Atlanta, GA !