Group Policy size in SYSVOL folder with PowerShell


$startfolder = “\\lab-dc01\SYSVOL\LAB.NET\Policies\*”

Change lab-dc01\sysvol\lab.net so it matches your environment. Also make sure you leave the final * in there as it ensures that the script only loops 1 level deep.

 

# =====================================================================
#
# Script Name : GetGPSize.ps1
# Purpose:Group Policy folders stored in SYSVOL

# =====================================================================

Function Get-GPOSize() {

$startfolder = "\\tnt.com\SYSVOL\tnt.com\Policies\*"
$folders = get-childitem $startfolder | where{$_.PSiscontainer -eq "True"}

foreach ($fol in $Folders){
$colItems = (Get-ChildItem $fol.fullname -recurse | Measure-Object -property length -sum)
$size = "{0:N2}" -f ($colItems.sum / 1KB) + " KB"
$guid = split-path $fol.fullname -leaf

$guid1 = [System.Text.RegularExpressions.Regex]::Replace($guid,"[({})]"," ");

if (Test-Path ($fol.fullname + "\gpt.ini"))
	{
	 $Gpname = Get-GPO -Guid $guid1  | Select-Object -ExpandProperty DisplayName -ErrorAction silentlycontinue | out-string -stream

	# Get-GPO -Guid $guid1 $GPO.DisplayName
	# $($fol.fullname)

	}
else
	{
	$Gpname = "No GPT.INI found"
	}
	$object = New-Object -TypeName PSObject
        $object | Add-Member -MemberType NoteProperty  -Name GPName -Value $Gpname
        $object | Add-Member -MemberType NoteProperty  -Name GPGUID -Value $guid1
        $object | Add-Member -MemberType NoteProperty -Name Size -Value $size
        $object
}
}

Get-GPOSize | Sort-object -property GPName | Format-Table -Property * -autosize

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: