I have accidentally imported my AD into root folder so i have alot of OUs that are empty, but cant remove them as i get a message saying “root cannot be deleted”
I cant find them with the terminal that will not list them.
you will need to use a bit of scripting for this. Do you have the IDs of the “root” folders that you want to delete? If so, you should be able to do so with the following script:
import net.datenwerke.security.service.usermanager.entities.OrganisationalUnit;
import net.datenwerke.security.service.usermanager.UserManagerService;
def ouID = 236082L; // note the L to ensure it is treated as Long
def userService = GLOBALS.getInstance(UserManagerService.class);
def ou = GLOBALS.findEntity(OrganisationalUnit.class, ouID);
userService.forceRemove(ou);
"deleted " + ouID
This should bypass the check whether or not the node to be deleted is a “root” node.
Good point. The LDAP sample script write protects any imported objects, such that they are not accidentally deleted/changed. In order to delete them, you would need to remove the write protection. Following is the adapted script, that does exactly this.
import net.datenwerke.security.service.usermanager.entities.OrganisationalUnit;
import net.datenwerke.security.service.usermanager.UserManagerService;
def ouID = 236082L; // note the L to ensure it is treated as Long
def userService = GLOBALS.getInstance(UserManagerService.class);
def ou = GLOBALS.findEntity(OrganisationalUnit.class, ouID);
/* remove write protection */
def remWP;
remWP = { node ->
node.setWriteProtection(false);
node.getChildren().each{ remWP(it) }
}
remWP(ou);
/* now that write protection is removed, nodes can be deleted */
userService.forceRemove(ou);
"deleted " + ouID