Answered DSQUERY script question

  • Friday, May 04, 2012 7:20 PM
     
     

    I'm having a problem with a little .cmd script I created to export group membership to a file.  If this is not the best place for this question, please let me know what forum this would best go under.  Here is the code:

    @echo off
    Set /P groupname=Please enter group name:
    echo The group name is %groupname%
    dsquery group –name %groupname% | dsget group –members -expand > %groupname%.txt
    pause

    Pretty simple little script that should save the expanded membership of an AD group into a file named for the group.  The problem is that I get the following error when I run the .cmd:

    Please enter group name:$GRP$RES$STS2000118Witness-Change
    The group name is $GRP$RES$STS2000118Witness-Change
    dsquery failed:'$GRP$RES$STS2000118Witness-Change' is an unknown parameter.
    type dsquery /? for help.dsget failed:Value for 'Target object for this command'
     has incorrect format.
    type dsget /? for help.Press any key to continue . . .

    The variable is being recognized properly, and the filename is being created with the proper name.  If I just type the following into the DOS prompt "dsquery group –name $GRP$RES$STS2000118Witness-Change | dsget group –members -expand > $GRP$RES$STS2000118Witness-Change.txt" everything will work fine.  I think the problem has something to do with the way the variable is being passed to the dsquery command, but screwed if I know what the issue is.  Any help woudl be appreciated.


    • Edited by jadedpuppy Friday, May 04, 2012 7:20 PM
    •  

All Replies

  • Friday, May 04, 2012 8:04 PM
     
     Answered

    Hello,

    You can try this one:

    @echo off
    Set /P groupname=Please enter group name:
    echo The group name is %groupname%
    echo dsquery.exe * -filter "(&(samaccountname= %groupname% ))" -attr member
    dsquery.exe * -filter "(&(samaccountname=%groupname%))" -attr member  > %groupname%.txt
    pause


    This posting is provided "AS IS" with no warranties or guarantees , and confers no rights.   

    Microsoft Student Partner 2010 / 2011
    Microsoft Certified Professional
    Microsoft Certified Systems Administrator: Security
    Microsoft Certified Systems Engineer: Security
    Microsoft Certified Technology Specialist: Windows Server 2008 Active Directory, Configuration
    Microsoft Certified Technology Specialist: Windows Server 2008 Network Infrastructure, Configuration
    Microsoft Certified Technology Specialist: Windows Server 2008 Applications Infrastructure, Configuration
    Microsoft Certified Technology Specialist: Windows 7, Configuring
    Microsoft Certified Technology Specialist: Designing and Providing Volume Licensing Solutions to Large Organizations
    Microsoft Certified IT Professional: Enterprise Administrator
    Microsoft Certified IT Professional: Server Administrator
    Microsoft Certified Trainer


    • Edited by Mr XMVP Friday, May 04, 2012 8:19 PM
    • Marked As Answer by Miya YaoModerator Thursday, May 17, 2012 8:29 AM
    •  
  • Saturday, May 05, 2012 6:26 AM
     
     Answered

    If you are looking for assistance with scripting, you might want to refer to the PowerShell forum

    http://social.technet.microsoft.com/Forums/en/winserverpowershell/threads

    http://social.technet.microsoft.com/Forums/en-US/category/scripting

    Hope this helps


    Best Regards,

    Sandesh Dubey.

    MCSE|MCSA:Messaging|MCTS|MCITP:Enterprise Adminitrator | My Blog

    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees , and confers no rights.