GPMgmt.vbs (In the book)

Download file: gpmgmt.vbs (3 Kb)

'Script : GPMgmt.vbs
'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!

' Global variables
Dim gpm, gpmConstants, gpmDomain
Dim RootDSE, adsiDomain, dnsDomain
Dim adsiForestRoot, dnsForestRoot

Const UseDate = True
Const NoDate = False

' Global Subroutines and Functions
Sub CreateGPMObjects
Set gpm = CreateObject("gpmgmt.gpm")
Set gpmConstants = gpm.GetConstants
Set RootDSE = GetObject("LDAP://RootDSE")
adsiDomain = RootDSE.Get("defaultNamingContext")
dnsDomain = ConvertToDNS(adsiDomain)
adsiForestRoot = RootDSE.Get("rootDomainNamingContext")
dnsForestRoot = ConvertToDNS(adsiForestRoot)
Set gpmDomain = gpm.GetDomain(dnsDomain,"",gpmConstants.UsePDC)
End Sub

Function GetGPOBackups(BackupFolder)
Set gpmSearchCriteria = gpm.CreateSearchCriteria()
gpmSearchCriteria.Add _
gpmConstants.SearchPropertyBackupMostRecent, gpmConstants.SearchOPEquals, True

Set gpmBackupDir = gpm.GetBackupDir(BackupFolder)
Set GetGPOBackups = gpmBackupDir.SearchBackups(gpmSearchCriteria)
End Function

Function ConvertToDNS (distinguishedName)
ConvertToDNS = Replace(Replace(distinguishedName,"DC=",""),",",".")
End Function

Function ConvertSOMType(SOMType)
Select Case SOMType
Case gpmConstants.SOMDomain : ConvertSOMType = "Domain"
Case gpmConstants.SOMOU : ConvertSOMType = "OU"
Case gpmConstants.SOMSite : ConvertSOMType = "Site"
End Select
End Function

Function ConvertTrusteeType(trusteeValue)
Select Case trusteeValue
Case 1 : ConvertTrusteeType = "User"
Case 2 : ConvertTrusteeType = "Group"
Case 3 : ConvertTrusteeType = "Domain"
Case 4 : ConvertTrusteeType = "Domain Local Group"
Case 5 : ConvertTrusteeType = "Well Known Group"
Case 6 : ConvertTrusteeType = "Deleted Account"
Case 7 : ConvertTrusteeType = "Invalid"
Case 8 : ConvertTrusteeType = "Unknown"
Case 9 : ConvertTrusteeType = "Computer"
End Select
End Function

Function ConvertAccessSetting(PermValue)
Select Case PermValue
Case gpmConstants.PermGPOApply
ConvertAccessSetting = "Apply"
Case gpmConstants.PermGPOCustom
ConvertAccessSetting = "Custom"
Case gpmConstants.PermGPOEdit
ConvertAccessSetting = "Edit"
Case gpmConstants.PermGPOEditSecurityandDelete
ConvertAccessSetting = "Edit and Delete"
Case gpmConstants.PermGPORead
ConvertAccessSetting = "Read"
End Select
End Function

Function GetDateName
GetDateName = Year(Now) & "-" & MonthName(Month(Now)) & "-" & Day(Now)
End Function

Sub CheckCScript
If InStr(WScript.FullName,"cscript.exe") = 0 Then
WScript.Echo "This script should be run from the command line with the CSCRIPT command."
WScript.Quit
End If
End Sub

Function FolderExists(Folder)
Set FSO = CreateObject("Scripting.FileSystemObject")
If FSO.FolderExists(Folder) Then
FolderExists = True
Else
FolderExists = False
End If
End Function

Function GetOU(distinguishedName)
On Error Resume Next
Set GetOU = GetObject("LDAP://" & distinguishedName)
If Err.Number <> 0 Then
Set GetOU = Nothing
End If
End Function

Function StripInvalidChars(gpoName)
Set RX = New RegExp
With RX
.Pattern = "[/\\|<>:?*]\"""
.IgnoreCase = True
.Global = True
End With
StripInvalidChars = Rx.Replace(gpoName, "-")
Set RX = Nothing
End Function
 

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 !