Create_and_Link_New_GPO.wsf (In the book)

Download file: create_and_link_new_gpo.wsf (2 Kb)

<job>
<comment>
Script : List_GPMC_Information.wsf
From the book "Group Policy" by Jeremy Moskowitz

The contents of this script are provided "as is".
No warranty of any kind, either express or implied, is made in relation
to the availability, accuracy, reliability or content of this script.
ALWAYS test scripts before using in your production network!
</comment>
<runtime>
<description>Create a new GPO and link to a designated OU.</description>
<named name="OU"
helpstring="Distinguished Name of the OU to link to."
type="string" required="true" />
<named name="GPO"
helpstring="Name of GPO to create."
type="string" required="true" />
<named name="TOP"
helpstring="Set new GPO on top of precedence."
type="simple" required="false" />
</runtime>

<script language="VBScript" src="/GPMgmt.vbs" />
<script>
CheckCScript
CreateGPMObjects

If WSH.Arguments.Count > 0 Then
If WSH.Arguments.Named.Exists("OU") Then
OUName = WSH.Arguments.Named("OU")
Else
ShowUsage
End If
If WSH.Arguments.Named.Exists("GPO") Then
GPOName = WSH.Arguments.Named("GPO")
Else
ShowUsage
End If
If WSH.Arguments.Named.Exists("Top") Then
LinkPrecedence = 1
Else
LinkPrecedence = -1
End If
Else
ShowUsage
End If

Set OU = GetOU(OUName)
If OU Is Nothing Then
WScript.Echo "Unable to bind to OU " & OUName
WScript.Quit
End If
Set NewGPO = gpmDomain.CreateGPO()
NewGPO.DisplayName = GPOName
Set SOM = gpmDomain.GetSOM(OU.distinguishedName)

On Error Resume Next
Set SOM_Link = SOM.CreateGPOLink(LinkPrecedence, NewGPO)
If Err.Number = 0 Then
WScript.Echo "Successfully linked " & NewGPO.DisplayName & " to " & SOM.Name & "."
Else
WScript.Echo "An error occurred while linking to OU."
End If

Sub ShowUsage
WScript.Echo "Usage:"
WScript.Echo "CSCRIPT.EXE //nologo /OU:Path_To_OU /GPO:GPO_Name [/TOP]"
WScript.Quit
End Sub
</script>
</job>
 

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 !