Create_and_Link_New_GPO.hta (In the book)

Download file: create_and_link_new_gpo.hta (3 Kb)

<HTML>
<HEAD>
<!--
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!
-->
<TITLE>Create and Link New GPO</TITLE>
<HTA:APPLICATION ID="Create and Link New GPO"
APPLICATIONNAME="Create and Link New GPO"
BORDER="dialog"
CAPTION="yes"
CONTEXTMENU="yes"
ICON="graphics/title.ico"
INNERBORDER="yes"
MINIMIZEBUTTON="yes"
MAXIMIZEBUTTON="yes"
SCROLLABLE="yes"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="yes"
WINDOWSTATE="maximize">
<LINK href='GroupPolicy.css' rel="stylesheet" type="text/css">
<SCRIPT src='GPMgmt.vbs' language="VBScript"></SCRIPT>
<SCRIPT src='HTA_Help.vbs' language="VBScript"></SCRIPT>
</HEAD>
<BODY>
<SCRIPT language="VBScript">
Dim gpm, gpmConstants

Sub Window_OnLoad
self.resizeTo 600,400
CreateGPMObjects
ouName.Value = adsiDomain
End Sub

Sub CreateLink
Dim Results_HTML

Set OU_To_Link = GetOU(OUName.Value)
If OU_To_Link Is Nothing Then
MsgBox OUName.Value & " was not found.", vbExclamation, "OU Not Found!"
Exit Sub
End If

Set NewGPO = gpmDomain.CreateGPO()
NewGPO.DisplayName = GPOName.Value
AddHTML Results_HTML, "<p>A GPO with the friendly name '" & NewGPO.DisplayName & "' has been created."
With NewGPO
AddHTML Results_HTML, "<ul>"
AddHTML Results_HTML, "<li>GUID: " & .ID
AddHTML Results_HTML, "<li>ADSI path: " & .Path
AddHTML Results_HTML, "</ul>"
End With
AddHTML Results_HTML, "<br>"

Set SOM = gpmDomain.GetSOM(OU_To_Link.distinguishedName)
If TopLink.Checked Then
GPOPrecedence = 1
Else
GPOPrecedence = -1
End If

AddHTML Results_HTML, "<p>Linking the GPO " & NewGPO.DisplayName & " to an " & ConvertSOMType(SOM.Type) & " container called " & SOM.Name & "."

On Error Resume Next
Set SOM_Link = SOM.CreateGPOLink(GPOPrecedence, NewGPO)

If Err.Number = 0 Then
AddHTML Results_HTML, "<p>Successfully linked " & NewGPO.DisplayName & " To " & SOM.Name & "."
MsgBox "Successfully linked " & NewGPO.DisplayName & " To " & SOM.Name & "."
Else
AddHTML Results_HTML, "<p>An error occurred while linking to OU:" & Err.Description & "(Error:" & Err.Number & ")"
MsgBox "An error occurred while linking to OU:" & Err.Description & "(Error:" & Err.Number & ")"
End If
Results_Span.innerHTML = Results_HTML
End Sub

</SCRIPT>
<p><div class="Title">Create and Link New GPO</div></p>
<p>
<div class="Heading">Enter OU and GPO information.</div>
<table>
<tr>
<td>OU Name:</td>
<td><input type="text" size="50" id="OUName"></td>
</tr>
<tr>
<td>GPO Name:</td>
<td><input type="text" size="30" id="GPOName"></td>
</tr>
<tr>
<td> </td>
<td><input type="checkbox" id="TopLink">Assign GPO Link to top of precedence list.</input></td>
</tr>
<tr>
<td> </td>
<td>
<button id="CreateLink" onClick="CreateLink()">Create Link</button>
</td>
</tr>
</table>
<ul>
<span id="Results_Span"></span>
</ul>
</p>

</BODY>
</HTML>
 

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 !