bsharath
asked on
Move groups from 1 ou to another. I have the user script. Can anyone help me with a group change.
Hi,
Move groups from 1 ou to another. I have the user script. Can anyone help me with a group change.
The below script works fine for Users
Can the same be changed to work on groups.
Regards
Sharath
Move groups from 1 ou to another. I have the user script. Can anyone help me with a group change.
The below script works fine for Users
Can the same be changed to work on groups.
Regards
Sharath
:: SCRIPT START
@ECHO OFF
SETLOCAL EnableDelayedExpansion
:: Following variables required to be set with actual values
SET NewOU=M00
IF EXIST UserMoveRpt.txt DEL /F /Q UserMoveRpt.txt
ECHO %NewOU%|FIND /I "OU=">NUL
IF NOT ERRORLEVEL 1 (
DSQuery OU "%NewOU%" 2>NUL |FIND /I "OU=" >NUL
IF NOT ERRORLEVEL 1 (DSQuery OU "%NewOU%" >OUTmpVar.txt &SET /P OUDN=<OUTmpVar.txt
) ELSE (ECHO Invalid OU distinguished name. &Goto :EndScript)
)ELSE (
DSQuery OU -Name "%NewOU%" |FIND /I "OU=" >NUL
IF NOT ERRORLEVEL 1 (DSQuery OU -Name "%NewOU%" >OUTmpVar.txt &SET /P OUDN=<OUTmpVar.txt
)ELSE (ECHO Invalid OU Name. &Goto :EndScript)
)
FOR /F "delims=*" %%u IN ('TYPE UserIDs.txt') DO (
ECHO Processing: %%u
DSQuery User -samID "%%u" |Find /I "CN=" >NUL
IF NOT ErrorLevel 1 (
DSQuery User -samID "%%u" |DSMove -newparent !OUDN! >>UserMoveRpt.txt
)ELSE (ECHO *ERROR* '%%u' Not Found in Active Directory.))
ECHO.&ECHO Script complete. Check 'UserMoveRpt.txt' file.
:EndScript
IF EXIST OUTmpVar.txt DEL /F /Q OUTmpVar.txt
ENDLOCAL
EXIT /B 0
:: *** SCRIPT END ***
Try this, with the Group Names in groupnames.txt
Regards,
Rob.
Regards,
Rob.
:: SCRIPT START
@ECHO OFF
SETLOCAL EnableDelayedExpansion
:: Following variables required to be set with actual values
SET NewOU=M00
IF EXIST GroupMoveRpt.txt DEL /F /Q GroupMoveRpt.txt
ECHO %NewOU%|FIND /I "OU=">NUL
IF NOT ERRORLEVEL 1 (
DSQuery OU "%NewOU%" 2>NUL |FIND /I "OU=" >NUL
IF NOT ERRORLEVEL 1 (DSQuery OU "%NewOU%" >OUTmpVar.txt &SET /P OUDN=<OUTmpVar.txt
) ELSE (ECHO Invalid OU distinguished name. &Goto :EndScript)
)ELSE (
DSQuery OU -Name "%NewOU%" |FIND /I "OU=" >NUL
IF NOT ERRORLEVEL 1 (DSQuery OU -Name "%NewOU%" >OUTmpVar.txt &SET /P OUDN=<OUTmpVar.txt
)ELSE (ECHO Invalid OU Name. &Goto :EndScript)
)
FOR /F "delims=*" %%u IN ('TYPE GroupNames.txt') DO (
ECHO Processing: %%u
DSQuery Group -name "%%u" |Find /I "CN=" >NUL
IF NOT ErrorLevel 1 (
DSQuery Group -name "%%u" |DSMove -newparent !OUDN! >>GroupMoveRpt.txt
)ELSE (ECHO *ERROR* '%%u' Not Found in Active Directory.))
ECHO.&ECHO Script complete. Check 'GroupMoveRpt.txt' file.
:EndScript
IF EXIST OUTmpVar.txt DEL /F /Q OUTmpVar.txt
ENDLOCAL
EXIT /B 0
:: *** SCRIPT END ***
ASKER
Thanks Rob
But groups are in the root Domain
But groups are in the root Domain
ASKER
Can you please have a look at these
https://www.experts-exchange.com/questions/25631574/Add-X500-for-a-user.html?cid=1575&anchorAnswerId=29275293#a29275293
https://www.experts-exchange.com/questions/25625020/Get-the-X500-details-of-all-users-in-a-txt-file-In-Colum-B-C-D-and-So-on.html?cid=1575&anchorAnswerId=29275875#a29275875
https://www.experts-exchange.com/questions/25631574/Add-X500-for-a-user.html?anchorAnswerId=29270517#a29270517
https://www.experts-exchange.com/questions/25631574/Add-X500-for-a-user.html?cid=1575&anchorAnswerId=29275293#a29275293
https://www.experts-exchange.com/questions/25625020/Get-the-X500-details-of-all-users-in-a-txt-file-In-Colum-B-C-D-and-So-on.html?cid=1575&anchorAnswerId=29275875#a29275875
https://www.experts-exchange.com/questions/25631574/Add-X500-for-a-user.html?anchorAnswerId=29270517#a29270517
If you run this from a command prompt to find a specific group name, what is the output:
adfind -gcb -f "&(objectclass=group)(name =YourGroup Name)" distinguishedName
Replace YourGroupName with one of the group names in the root domain, and see if it finds it.
Regards,
Rob.
adfind -gcb -f "&(objectclass=group)(name
Replace YourGroupName with one of the group names in the root domain, and see if it finds it.
Regards,
Rob.
ASKER
Yes 1 object found
OK, try this.
Regards,
Rob.
Regards,
Rob.
:: SCRIPT START
@ECHO OFF
SETLOCAL EnableDelayedExpansion
:: Following variables required to be set with actual values
SET NewOU=OU=TestOU,DC=Maroondah,DC=Local
IF EXIST GroupMoveRpt.txt DEL /F /Q GroupMoveRpt.txt
ECHO %NewOU%|FIND /I "OU=">NUL
IF NOT ERRORLEVEL 1 (
DSQuery OU "%NewOU%" 2>NUL |FIND /I "OU=" >NUL
IF NOT ERRORLEVEL 1 (DSQuery OU "%NewOU%" >OUTmpVar.txt &SET /P OUDN=<OUTmpVar.txt
) ELSE (ECHO Invalid OU distinguished name. &Goto :EndScript)
)ELSE (
DSQuery OU -Name "%NewOU%" |FIND /I "OU=" >NUL
IF NOT ERRORLEVEL 1 (DSQuery OU -Name "%NewOU%" >OUTmpVar.txt &SET /P OUDN=<OUTmpVar.txt
)ELSE (ECHO Invalid OU Name. &Goto :EndScript)
)
FOR /F "delims=*" %%u IN ('TYPE GroupNames.txt') DO (
ECHO Processing: %%u
adfind -gcb -f "&(objectclass=group)(name=%%u)" -dn | find /I "dn:" >NUL
IF NOT ErrorLevel 1 (
adfind -gcb -f "&(objectclass=group)(name=%%u)" -dn | find /I "dn:" > GroupDN.txt
for /f "tokens=*" %%k in (GroupDN.txt) DO (
for /f "tokens=1 delims=;" %%l in ("%%k") DO (
for /f "tokens=2 delims=:" %%m in ("%%l") do (
rem echo moving %%m to !OUDN!
DSMove %%m -newparent !OUDN! >>GroupMoveRpt.txt
)
)
)
)ELSE (ECHO *ERROR* '%%u' Not Found in Active Directory.)
)
ECHO.&ECHO Script complete. Check 'GroupMoveRpt.txt' file.
:EndScript
IF EXIST OUTmpVar.txt DEL /F /Q OUTmpVar.txt
IF EXIST GroupDN.txt DEL /F /Q GroupDN.txt
ENDLOCAL
EXIT /B 0
:: *** SCRIPT END ***
ASKER
Rob i get this
Processing: Coi_fs
AdFind V01.36.00cpp Joe Richards (joe@joeware.net) February 2007
AdFind V01.36.00cpp Joe Richards (joe@joeware.net) February 2007
dsmove failed:`Distribution' is an unknown parameter.
type dsmove /? for help.
Script complete. Check 'GroupMoveRpt.txt' file.
Press any key to continue . . .
Processing: Coi_fs
AdFind V01.36.00cpp Joe Richards (joe@joeware.net) February 2007
AdFind V01.36.00cpp Joe Richards (joe@joeware.net) February 2007
dsmove failed:`Distribution' is an unknown parameter.
type dsmove /? for help.
Script complete. Check 'GroupMoveRpt.txt' file.
Press any key to continue . . .
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Rob works perfect
Any help on others
Any help on others
ASKER
Hi Rob..
I dont know why groups are not moving but the log shows success.
Any help please...Is this specific to a group type like distribution or security or mail enabled only ?
I dont know why groups are not moving but the log shows success.
Any help please...Is this specific to a group type like distribution or security or mail enabled only ?
The DSMove command should not be showing success if it doesn't actually move the group.....do you have to wait for replication to occur before you can see that it has moved?
With a group that hasn't moved, is it a Distribution group, Security group, or mail enabled group? Can you check a few?
Rob.
With a group that hasn't moved, is it a Distribution group, Security group, or mail enabled group? Can you check a few?
Rob.
::to delete user from Group
net group <groupname> <userName> /domain /delete
::to Add user
net group <groupname> <userName> /domain /add
something like this
@echo off
for /f "delims=|" %%i in (userList.txt) do (
net group <groupnametoremove> %%i /domain /delete
net group <groupnametoadd> %%i /domain /delete)
???