Set-GPEnvironment.ps1

Jan
24
2013

# Set-GPEnvironment
# Writen By Brandon Shell(www.BSonPosh.com)
# Sets GPO Environment
function Convert-DNToDNS{$args[0] -replace “DC=”,”" -replace “,”,”.”}
function Convert-GPSOMType {
Param($SOMType)
switch ($SOMType)
{
$gpmConstants.SOMDomain  {“Domain”}
$gpmConstants.SOMOU      {“OU”}
$gpmConstants.SOMSite    {“Site”}
Default                  {“Domain”}
}
}
function Convert-GPTrusteeValue {
Param($trusteeValue)
switch ($trusteeValue)
{
1 {“User”}
2 {“Group”}
3 {“Domain”}
4 {“Domain Local Group”}
5 {“Well Known Group”}
6 {“Deleted Account”}
7 {“Invalid”}
8 {“Unknown”}
9 {“Computer”}
}
}
function Convert-GPPermValue {
Param($PermValue)
switch ($PermValue)
{
$gpmConstants.PermGPOApply                  {“Apply”}
$gpmConstants.PermGPOCustom                 {“Custom”}
$gpmConstants.PermGPOEdit                   {“Edit”}
$gpmConstants.PermGPOEditSecurityandDelete  {“Edit and Delete”}
$gpmConstants.PermGPORead                   {“Read”}
}
}
function Get-GPOBackups{
Param($BackupFolder)
$gpmSearchCriteria = $gpm.CreateSearchCriteria()
$gpmSearchCriteria.Add($gpmConstants.SearchPropertyBackupMostRecent,$gpmConstants.SearchOPEquals,$True)
$gpmBackupDir = $gpm.GetBackupDir($BackupFolder)
$gpmBackupDir.SearchBackups($gpmSearchCriteria)
}

# Global
$gpm = new-object -ComObject “gpmgmt.gpm”
$gpmConstants = $gpm.GetConstants()
$rootDSE = [ADSI]“LDAP://rootDSE
$ADSIDomain = $rootDSE.defaultNamingContext
$dnsDomain = Convert-DNToDNS $ADSIDomain
$ADSIForestRoot = $rootDSE.rootDomainNamingContext
$dnsForestRoot = Convert-DNToDNS $ADSIForestRoot
$gpmDomain = $gpm.GetDomain($dnsDomain,$null,$gpmConstants.UsePDC)