Questions

dsquery dsmove

+
0 Votes
Locked

dsquery dsmove

craig.parkinson
can you see anything wrong here?

dsquery computer -disabled -limit 200 | dsmove computer -newparent "ou=desktops,ou=workstations,DC=ad,DC=firmname,DC=com"

i sure cant but for some unknown reason all the time i get


dsquery computer -disabled -limit 200 | dsmove computer -newparent "ou=deskt
ops,ou=workstations,DC=ad,DC=firmname,DC=com"
dsmove failed:Value for `Target object for this command' has incorrect format.
type dsmove /? for help.
  • +
    0 Votes

    dsmove.exe "CN=%1,OU=aaa,DC=AA,DC=BB,DC=com" -newparent
    OU=bbb,DC=AA,dc=BB,dc=com


    Copied from:
    http://blogs.technet.com/jhoward/archive/2005/01/27/361415.aspx

    Sample scripts for dsadd, dsmodify, dsget, dsquery, dsmod, dsmove

    Following my Technet session on the New Features of Windows Server 2003 Active Directory, scenario based, here's the scripts which I promised to post up. Hope they are useful. Even if you didn't attend the session, they give you a good example of how these command line programs can be used. Remember that the Windows Server Help and Support has very detailed information on the parameters to these commands - often overlooked when people head straight over to their favourite Internet search engine....

    AddUsers.bat

    dsadd ou "OU=Sales,DC=worldwideimporters,DC=com"
    dsadd ou "OU=Marketing and Finance,DC=worldwideimporters,DC=com"
    dsadd user "CN=KimA,OU=Sales,DC=worldwideimporters,DC=com"
    dsadd user "CN=SeanA,Ou=Sales,DC=worldwideimporters,DC=com"
    dsadd user "CN=NeilC,Ou=Sales,DC=worldwideimporters,DC=com"
    dsadd user "CN=AaronC,Ou=Sales,DC=worldwideimporters,DC=com"
    dsadd user "CN=AndrewH,Ou=Sales,DC=worldwideimporters,DC=com"
    dsadd user "CN=DonH,Ou=Marketing and Finance,DC=worldwideimporters,DC=com"
    dsadd user "Cn=GarthF,Ou=Marketing and Finance,DC=worldwideimporters,DC=com"
    dsadd user "CN=MarkH,Ou=Marketing and Finance,DC=worldwideimporters,DC=com"
    dsadd user "CN=JoB,Ou=Marketing and Finance,DC=worldwideimporters,DC=com"
    dsadd user "CN=ScottC,Ou=Marketing and Finance,DC=worldwideimporters,DC=com"
    dsadd group "CN=Sales Users,CN=users,DC=worldwideimporters,DC=com" -scope g
    dsadd group "CN=Marketing and Finance Users,CN=users,DC=worldwideimporters,DC=com" -scope g
    dsadd group "CN=Sales Data,CN=users,DC=worldwideimporters,DC=com" -scope l
    dsadd group "CN=Marketing and Finance Data,CN=users,DC=worldwideimporters,DC=com" -scope l
    dsadd computer "CN=SALESWKSTN1,OU=Sales,DC=worldwideimporters,DC=com"
    dsadd computer "CN=SALESWKSTN2,OU=Sales,DC=worldwideimporters,DC=com"
    dsadd computer "CN=MAFWKSTN1,OU=Marketing and Finance,DC=worldwideimporters,DC=com"
    dsadd computer "CN=MAFWKSTN2,OU=Marketing and Finance,DC=worldwideimporters,DC=com"

    ModifyMembers.bat

    dsmod group "CN=Marketing and Finance users,CN=users,DC=worldwideimporters,DC=com" -addmbr "CN=KimA,OU=Marketing and Finance,DC=worldwideimporters,DC=com" "CN=SeanA,OU=Marketing and Finance,DC=worldwideimporters,DC=com" "CN=AaronC,OU=Marketing and Finance,DC=worldwideimporters,DC=com"
    dsmod user "CN=KimA,OU=Marketing and Finance,DC=worldwideimporters,Dc=com" "CN=SeanA,OU=Marketing and Finance,DC=worldwideimporters,DC=com" "CN=AaronC,OU=Marketing and Finance,DC=worldwideimporters,DC=com" -pwd Abcd123 -mustchpwd yes

    MoveUsers.bat

    dsmove "CN=KimA,OU=Sales,DC=worldwideimporters,DC=com" -newparent "OU=Marketing and Finance,DC=worldwideimporters,DC=com"
    dsmove "CN=AaronC,OU=Sales,DC=worldwideimporters,DC=com" -newparent "OU=Marketing and Finance,DC=worldwideimporters,DC=com"
    dsmove "CN=SeanA,OU=Sales,DC=worldwideimporters,DC=com" -newparent "OU=Marketing and Finance,DC=worldwideimporters,DC=com"ModifyMembers.bat

    QueryUsers.bat

    dsget user "CN=KimA,OU=Sales,DC=worldwideimporters,DC=Com" -memberof -expand >"c:\documents and Settings\All Users\Desktop\userinfo.txt"
    dsquery user "OU=Sales,DC=worldwideimporters,DC=com" >>"c:\documents and Settings\All Users\Desktop\userinfo.txt"
    dsquery user "OU=Marketing and Finance,DC=worldwideimporters,DC=com" >>"c:\documents and Settings\All Users\Desktop\userinfo.txt"
    Notepad "c:\documents and Settings\All Users\Desktop\userinfo.txt"

    Remove1.bat

    dsrm -noprompt -c "cn=KimA,OU=Marketing and Finance,DC=worldwideimporters,DC=com"
    dsrm -noprompt -c "CN=mafwkstn1,OU=Marketing and Finance,DC=worldwideimporters,DC=com"
    dsrm -noprompt -c "CN=Marketing and Finance Users,CN=Users,DC=worldwideimporters,DC=com"
    dsrm -subtree -noprompt -c "OU=Marketing and Finance,DC=worldwideimporters,DC=com"

    RemoveAll.bat

    dsrm -subtree -noprompt -c "OU=Sales,DC=worldwideimporters,DC=com"
    dsrm -noprompt -c "CN=Marketing and Finance Data,CN=Users,DC=worldwideimporters,DC=com"
    dsrm -noprompt -c "CN=Sales Users,CN=Users,DC=worldwideimporters,DC=com"
    dsrm -noprompt -c "CN=Sales data,CN=Users,DC=worldwideimporters,DC=com"

    Please post back if you have any more problems or questions.

    +
    0 Votes
    craig.parkinson

    moving one at a time would be a nightmare i could try a script to do it it but though ti would try the microsoft way

    +
    0 Votes

    Please post back if you have any more problems or questions.

    +
    0 Votes
    scott_heath

    It only works for one user. It's a problem with DOS. PowerShell allows you to use the _$ variable to handle on object at a time. The problem is that DSQUERY is piping ALL of the resonses the the DSMOVE command at one time.

    You can achieve what you want with a faitly simple VBScript:

    Set objConnection = CreateObject("ADODB.Connection")
    Set objCommand = CreateObject("ADODB.Command")
    objConnection.Provider = "ADsDSOObject"
    objConnection.Open "Active Directory Provider"
    Set objCommand.ActiveConnection = objConnection

    objCommand.Properties("Page Size") = 10000
    objCommand.Properties("Searchscope") = 2

    objCommand.CommandText = "SELECT ADsPath FROM 'LDAP://DC=firmname,DC=com' WHERE ObjectClass = 'Computer'"
    Set objRecordSet = objCommand.Execute

    objRecordSet.MoveFirst
    Do Until objRecordSet.EOF
    strADsPath = objRecordSet.Fields("ADsPath").Value
    Set objOU = GetObject("LDAP://ou=desktops,ou=workstations,DC=ad,DC=firmname,DC=com")
    objOU.MoveHere(strADsPath, vbNullString)
    objRecordSet.MoveNext
    Loop

    The only thing you need to do is figure out the filter you'll need to only get disabled accounts. If you can't find it let me know and I'll look it up. It's not terribly hard, but I figured I'd let you do it.

    http://msdn.microsoft.com/en-us/library/ms675768.aspx

    The alterative is to use the DSQUERY and DSMOVE commands in a VBScript and dump the contents of DSMOVE to a file and then read one line at a time and execute the DSMOVE. If you would rather go this way, let me know.

    Cheers,
    Scott

    Visit my blog @
    http://scottisageek.spaces.live.com

    +
    0 Votes
    jliderson

    I just want to query for users who are inactive more than 5 weeks and move them to an organizational unit
    dsquery user -inactive 5 | dsmove -newparent OU=DISABLE,DC=xxxx,DC=xx

    +
    0 Votes
    LFBAdmin

    the commands below are actually creating a live variable to use each command as a bubble to complete the requested task. Variable one is encloses the dsquery command and captures the ending result, which is placed in the variable %s. This variable is then used by dsmove to execute a move function based on the results in the %s variable.

    This command will move all inactive computers to the new OU. But be careful with this command, for it does not differentiate between servers and actual user machines (unless specified in AD). The inactive zero means not logged in within the last 24 hours and limit 0 will display all results.

    for /f "Tokens=*" %s in ('dsquery computer -inactive 0 -limit 0') do DSMOVE %s -newparent "ou=computers,ou=inspections,dc=sccmtest,dc=org"


    This command will move all computers in the Manufacturing > Computers OU to the Inspections > Computers OU.

    for /f "Tokens=*" %s in ('dsquery computer "ou=computers,ou=manufacturing,dc=sccmtest,dc=org"') do DSMOVE %s -newparent "ou=computers,ou=inspections,dc=sccmtest,dc=org"

  • +
    0 Votes

    dsmove.exe "CN=%1,OU=aaa,DC=AA,DC=BB,DC=com" -newparent
    OU=bbb,DC=AA,dc=BB,dc=com


    Copied from:
    http://blogs.technet.com/jhoward/archive/2005/01/27/361415.aspx

    Sample scripts for dsadd, dsmodify, dsget, dsquery, dsmod, dsmove

    Following my Technet session on the New Features of Windows Server 2003 Active Directory, scenario based, here's the scripts which I promised to post up. Hope they are useful. Even if you didn't attend the session, they give you a good example of how these command line programs can be used. Remember that the Windows Server Help and Support has very detailed information on the parameters to these commands - often overlooked when people head straight over to their favourite Internet search engine....

    AddUsers.bat

    dsadd ou "OU=Sales,DC=worldwideimporters,DC=com"
    dsadd ou "OU=Marketing and Finance,DC=worldwideimporters,DC=com"
    dsadd user "CN=KimA,OU=Sales,DC=worldwideimporters,DC=com"
    dsadd user "CN=SeanA,Ou=Sales,DC=worldwideimporters,DC=com"
    dsadd user "CN=NeilC,Ou=Sales,DC=worldwideimporters,DC=com"
    dsadd user "CN=AaronC,Ou=Sales,DC=worldwideimporters,DC=com"
    dsadd user "CN=AndrewH,Ou=Sales,DC=worldwideimporters,DC=com"
    dsadd user "CN=DonH,Ou=Marketing and Finance,DC=worldwideimporters,DC=com"
    dsadd user "Cn=GarthF,Ou=Marketing and Finance,DC=worldwideimporters,DC=com"
    dsadd user "CN=MarkH,Ou=Marketing and Finance,DC=worldwideimporters,DC=com"
    dsadd user "CN=JoB,Ou=Marketing and Finance,DC=worldwideimporters,DC=com"
    dsadd user "CN=ScottC,Ou=Marketing and Finance,DC=worldwideimporters,DC=com"
    dsadd group "CN=Sales Users,CN=users,DC=worldwideimporters,DC=com" -scope g
    dsadd group "CN=Marketing and Finance Users,CN=users,DC=worldwideimporters,DC=com" -scope g
    dsadd group "CN=Sales Data,CN=users,DC=worldwideimporters,DC=com" -scope l
    dsadd group "CN=Marketing and Finance Data,CN=users,DC=worldwideimporters,DC=com" -scope l
    dsadd computer "CN=SALESWKSTN1,OU=Sales,DC=worldwideimporters,DC=com"
    dsadd computer "CN=SALESWKSTN2,OU=Sales,DC=worldwideimporters,DC=com"
    dsadd computer "CN=MAFWKSTN1,OU=Marketing and Finance,DC=worldwideimporters,DC=com"
    dsadd computer "CN=MAFWKSTN2,OU=Marketing and Finance,DC=worldwideimporters,DC=com"

    ModifyMembers.bat

    dsmod group "CN=Marketing and Finance users,CN=users,DC=worldwideimporters,DC=com" -addmbr "CN=KimA,OU=Marketing and Finance,DC=worldwideimporters,DC=com" "CN=SeanA,OU=Marketing and Finance,DC=worldwideimporters,DC=com" "CN=AaronC,OU=Marketing and Finance,DC=worldwideimporters,DC=com"
    dsmod user "CN=KimA,OU=Marketing and Finance,DC=worldwideimporters,Dc=com" "CN=SeanA,OU=Marketing and Finance,DC=worldwideimporters,DC=com" "CN=AaronC,OU=Marketing and Finance,DC=worldwideimporters,DC=com" -pwd Abcd123 -mustchpwd yes

    MoveUsers.bat

    dsmove "CN=KimA,OU=Sales,DC=worldwideimporters,DC=com" -newparent "OU=Marketing and Finance,DC=worldwideimporters,DC=com"
    dsmove "CN=AaronC,OU=Sales,DC=worldwideimporters,DC=com" -newparent "OU=Marketing and Finance,DC=worldwideimporters,DC=com"
    dsmove "CN=SeanA,OU=Sales,DC=worldwideimporters,DC=com" -newparent "OU=Marketing and Finance,DC=worldwideimporters,DC=com"ModifyMembers.bat

    QueryUsers.bat

    dsget user "CN=KimA,OU=Sales,DC=worldwideimporters,DC=Com" -memberof -expand >"c:\documents and Settings\All Users\Desktop\userinfo.txt"
    dsquery user "OU=Sales,DC=worldwideimporters,DC=com" >>"c:\documents and Settings\All Users\Desktop\userinfo.txt"
    dsquery user "OU=Marketing and Finance,DC=worldwideimporters,DC=com" >>"c:\documents and Settings\All Users\Desktop\userinfo.txt"
    Notepad "c:\documents and Settings\All Users\Desktop\userinfo.txt"

    Remove1.bat

    dsrm -noprompt -c "cn=KimA,OU=Marketing and Finance,DC=worldwideimporters,DC=com"
    dsrm -noprompt -c "CN=mafwkstn1,OU=Marketing and Finance,DC=worldwideimporters,DC=com"
    dsrm -noprompt -c "CN=Marketing and Finance Users,CN=Users,DC=worldwideimporters,DC=com"
    dsrm -subtree -noprompt -c "OU=Marketing and Finance,DC=worldwideimporters,DC=com"

    RemoveAll.bat

    dsrm -subtree -noprompt -c "OU=Sales,DC=worldwideimporters,DC=com"
    dsrm -noprompt -c "CN=Marketing and Finance Data,CN=Users,DC=worldwideimporters,DC=com"
    dsrm -noprompt -c "CN=Sales Users,CN=Users,DC=worldwideimporters,DC=com"
    dsrm -noprompt -c "CN=Sales data,CN=Users,DC=worldwideimporters,DC=com"

    Please post back if you have any more problems or questions.

    +
    0 Votes
    craig.parkinson

    moving one at a time would be a nightmare i could try a script to do it it but though ti would try the microsoft way

    +
    0 Votes

    Please post back if you have any more problems or questions.

    +
    0 Votes
    scott_heath

    It only works for one user. It's a problem with DOS. PowerShell allows you to use the _$ variable to handle on object at a time. The problem is that DSQUERY is piping ALL of the resonses the the DSMOVE command at one time.

    You can achieve what you want with a faitly simple VBScript:

    Set objConnection = CreateObject("ADODB.Connection")
    Set objCommand = CreateObject("ADODB.Command")
    objConnection.Provider = "ADsDSOObject"
    objConnection.Open "Active Directory Provider"
    Set objCommand.ActiveConnection = objConnection

    objCommand.Properties("Page Size") = 10000
    objCommand.Properties("Searchscope") = 2

    objCommand.CommandText = "SELECT ADsPath FROM 'LDAP://DC=firmname,DC=com' WHERE ObjectClass = 'Computer'"
    Set objRecordSet = objCommand.Execute

    objRecordSet.MoveFirst
    Do Until objRecordSet.EOF
    strADsPath = objRecordSet.Fields("ADsPath").Value
    Set objOU = GetObject("LDAP://ou=desktops,ou=workstations,DC=ad,DC=firmname,DC=com")
    objOU.MoveHere(strADsPath, vbNullString)
    objRecordSet.MoveNext
    Loop

    The only thing you need to do is figure out the filter you'll need to only get disabled accounts. If you can't find it let me know and I'll look it up. It's not terribly hard, but I figured I'd let you do it.

    http://msdn.microsoft.com/en-us/library/ms675768.aspx

    The alterative is to use the DSQUERY and DSMOVE commands in a VBScript and dump the contents of DSMOVE to a file and then read one line at a time and execute the DSMOVE. If you would rather go this way, let me know.

    Cheers,
    Scott

    Visit my blog @
    http://scottisageek.spaces.live.com

    +
    0 Votes
    jliderson

    I just want to query for users who are inactive more than 5 weeks and move them to an organizational unit
    dsquery user -inactive 5 | dsmove -newparent OU=DISABLE,DC=xxxx,DC=xx

    +
    0 Votes
    LFBAdmin

    the commands below are actually creating a live variable to use each command as a bubble to complete the requested task. Variable one is encloses the dsquery command and captures the ending result, which is placed in the variable %s. This variable is then used by dsmove to execute a move function based on the results in the %s variable.

    This command will move all inactive computers to the new OU. But be careful with this command, for it does not differentiate between servers and actual user machines (unless specified in AD). The inactive zero means not logged in within the last 24 hours and limit 0 will display all results.

    for /f "Tokens=*" %s in ('dsquery computer -inactive 0 -limit 0') do DSMOVE %s -newparent "ou=computers,ou=inspections,dc=sccmtest,dc=org"


    This command will move all computers in the Manufacturing > Computers OU to the Inspections > Computers OU.

    for /f "Tokens=*" %s in ('dsquery computer "ou=computers,ou=manufacturing,dc=sccmtest,dc=org"') do DSMOVE %s -newparent "ou=computers,ou=inspections,dc=sccmtest,dc=org"