New-GPO.ps1

Jan
24
2013

# New-GPO.ps1
# Writen By Brandon Shell (www.BSonPosh.com)
# Creates a New GPO by Name. Can be copied from another GPO
# Parameters
#  -GPOName: Name of the GPO
#  -FromGPO: Name of the GPO you Want to Copy From
# Switches
#  -Verbose: Enables Verbose Logging
# Requires Set-GPEnvironment.ps1
Param($GPOName = (Read-Host “Enter the Name of New GPO”),
$fromGPO,
[switch]$Verbose)
if($verbose){$verbosepreference = “continue”}
. “$pwd\Set-GPEnvironment.ps1″

if($fromGPO)
{
Write-Verbose “Getting <$fromGPO> Object”
$GPMsc = $gpm.CreateSearchCriteria()
#$GPMsc.Add($gpmConstants.SearchPropertyGPOUserExtensions,$gpmConstants.SearchOPContains,$id)
$GPOList = $GPMDomain.SearchGPOs($GPMsc)
$mgpo = $GPOList | where-Object{$_.DisplayName -eq $fromGPO}
$result = $mgpo.CopyTo(0,$gpmDomain,$GPOName) | %{$_.Result}
Write-Verbose “CopyTo Returned $($result.DisplayName)”
Write-Host (“GPO {0} Created” -f $result.DisplayName)
}
else
{
$NewGPO = $gpmDomain.CreateGPO()
$NewGPO.DisplayName = $GPOName
Write-Host (“GPO {0} Created” -f $NewGPO.DisplayName)
}

Copyright © GPanswers.com. All rights reserved. GPanswers.com is a service of PolicyPak Software