Solved

Using vbscript to set "Protect object from accidental deletion" for AD group

Posted on 2011-09-29
3
1,630 Views
Last Modified: 2012-05-12
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.
0
Comment
Question by:MortensonIT
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 39

Accepted Solution

by:
Krzysztof Pytko earned 500 total points
ID: 36817464
I have not tested it by myself but you can try to  do it on one group for test (if you wish) and check if it works for you

Run this command on a DC in command-line

for /f "tokens=*" %i in ('dsquery group -name "GroupName"') do dsacls %i /d everyone:SDDT

For reference, you may wish to read this blog at
http://msmvps.com/blogs/ulfbsimonweidner/archive/2007/09/25/protect-objects-from-accidential-deletion-in-windows-server-2008.aspx

Regards,
Krzysztof
0
 

Author Comment

by:MortensonIT
ID: 36817775
Nice. But, any way to do this without using dsacls? I'd like to run this from a vbscript that will be run on computer that don't necessarily have the dsacls functionality available.
0
 

Author Closing Comment

by:MortensonIT
ID: 36988285
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.Shell")
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
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains the steps required to use the default Photos screensaver to display branding/corporate images
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question