PoshCode Archive  Artifact [dcb73856a2]

Artifact dcb73856a20bc466ba10619a19ef4885c4ab1f108d8ef756f954f9f96c573ba4:

  • File get-GPOReportSize.ps1 — part of check-in [fa52fa127a] at 2018-06-10 13:33:53 on branch trunk — HTML report output for all (= default) or specific GPO (piped from Get-GPO) with folder size (user: chriskenis size: 1816)

# encoding: ascii
# api: powershell
# title: get-GPOReportSize
# description: HTML report output for all (= default) or specific GPO (piped from Get-GPO) with folder size
# version: 0.1
# type: script
# author: chriskenis
# license: CC0
# x-poshcode-id: 3980
# x-archived: 2013-02-28T00:46:12
# x-published: 2013-02-21T12:39:00
#
# output object contains URI to the reports
#
param(
[Parameter(Position=0,ValueFromPipeline=$True)]$GPOs = @(Get-GPO -All),
[string] $Reportfolder = [Environment]::getfolderpath("mydocuments") + "\GPOreports"
)

begin{
$script:GPObj = @()
$domain = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().Name
$startfolder = "\\$domain\SYSVOL\$domain\Policies"
write-verbose "getting info from $startfolder"

Function GPOSize($objGPO){
	$colItems = (Get-ChildItem "$("$startfolder\`{")$($objGPO.Id)$("`}")" -recurse | Measure-Object -property length -sum)
	$Result = "{0:N2}" -f ($colItems.sum / 1KB) + " KB"
	write-verbose "the size for $objGPO is $Result"
	return $Result
}
}# end begin

process{
foreach ($GPO in $GPOs){
	write-verbose "getting GPO $($GPO.DisplayName)"
	$DateRevMin = get-date -uformat "%Y-%m-%d"
	New-Item $Reportfolder\$DateRevMin -ItemType directory -Force | out-null
	$OutPath = $Reportfolder + "\" + $DateRevMin + "\" + $GPO.DisplayName + ".html"
	Get-GPOReport $GPO.Id -ReportType html -Path $OutPath
	$script:GPObj += New-Object PSObject -Property @{
		GPName = $GPO.DisplayName
		GPGUID = $GPO.ID
		Size = $(GPOSize $GPO)
		Report = $OutPath
		}
	}
}# end process

end{
$script:GPObj
}

# alternative oneliner to get reports for all GPO objects in domain
# Get-GPO -All | %{Get-GPOReport -guid $_.id -ReportType html -Path (join-path -path "c:\temp" -childpath "$($_.displayname).html")}