MortensonIT
asked on
Using vbscript to set "Protect object from accidental deletion" for AD group
Good morning.
I'm setting up a script to create groups in AD based on user input. How can I setup the script to put a checkmark in the box for "Protect this object from accidental deletion" on the Object tab for the properties of each group?
Thanks.
I'm setting up a script to create groups in AD based on user input. How can I setup the script to put a checkmark in the box for "Protect this object from accidental deletion" on the Object tab for the properties of each group?
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I ended up using that command within a script -- wasn't quite what I was expecting, but it works. Running that command within this script was taking quite a long time, though, so, rather than have this run every time on every gruop within the OU each time (which could end up taking a long time, as this OU could contain thousands of groups eventually), I setup the script to check when was the last time that the group was created -- if within the last 7 days, then run the command (I did 7 days in case the server where this script is setup as a Scheduled Task was unavailable for some reason -- figured that 7 days would be plenty of time to make sure that the server was available):
Dim oWshShell 'Windows Script Host Shell object
Set oWshShell = CreateObject("WScript.Shel l")
Dim sAbsolutePath
sAbsolutePath = oWshShell.CurrentDirectory
dtm7DaysAgo = Date() - 7
Set objOU = GetObject("LDAP://ou=Test, dc=Acme,dc =com")
objOU.Filter = Array("Group")
For Each objGroup In objOU
If objGroup.WhenCreated > dtmYesterday Or objGroup.WhenChanged > dtm7DaysAgo then
sGroup = replace(objGroup.Name, "CN=", "")
'wscript.echo sGroup & " - " & objGRoup.whencreated & " - " & objGroup.WhenChanged
oWshShell.Run "%comspec% /c for /f ""tokens=*"" %i in ('dsquery group ""ou=test,dc=acme,dc=com"" -name " & sGroup & "') do dsacls %i /d everyone:SDDT"
End If
Next
Dim oWshShell 'Windows Script Host Shell object
Set oWshShell = CreateObject("WScript.Shel
Dim sAbsolutePath
sAbsolutePath = oWshShell.CurrentDirectory
dtm7DaysAgo = Date() - 7
Set objOU = GetObject("LDAP://ou=Test,
objOU.Filter = Array("Group")
For Each objGroup In objOU
If objGroup.WhenCreated > dtmYesterday Or objGroup.WhenChanged > dtm7DaysAgo then
sGroup = replace(objGroup.Name, "CN=", "")
'wscript.echo sGroup & " - " & objGRoup.whencreated & " - " & objGroup.WhenChanged
oWshShell.Run "%comspec% /c for /f ""tokens=*"" %i in ('dsquery group ""ou=test,dc=acme,dc=com""
End If
Next
ASKER