locked
Query Active directoy users computers for all of my operating systems RRS feed

  • Question

  • Would like to run a query to show all of my operating systems for computers. If I run a saved query from aduc/define query and select advanced and edit the field to show Operating system and or operating system version it just shows host names.
    Monday, April 9, 2012 2:33 PM

Answers

  • Hi again,

    Since you are novice, I would recommend creating a batch file (a file which extension is .bat) and then add the following command in this file:

    for /f "Tokens=*" %%s in ('dsquery computer -limit 0') do (
    for /f "Tokens=*" %%P in ('dsquery * %%s -attr name ^|find /V "name"') do (

    for /f "Tokens=*" %%Q in ('dsquery * %%s -attr operatingSystemVersion ^|find /V "operatingSystemVersion"') do (

    for /f "Tokens=*" %%R in ('dsquery * %%s -attr operatingSystem ^|find /V "operatingSystem"') do (

    echo %%P; %%Q ; %%R >> c:\allcomputers.CSV
    )
    )
    )
    )

    Once done, run the script and then you will find a file under c:\ named allcomputers.csv where you will find three columns if you open it using Excel:

    • Column 1: Name
    • Column 2: Operating System Version
    • Column 3: Operating System

    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 Monday, April 9, 2012 4:06 PM
    • Marked as answer by Chicojrman1 Monday, April 9, 2012 5:34 PM
    Monday, April 9, 2012 4:06 PM
  • Moreover, below scripts can be used too.

    http://gallery.technet.microsoft.com/scriptcenter/Display-computers-status-c8ff289d

    http://gallery.technet.microsoft.com/scriptcenter/c79e9809-b8e8-4cf1-af07-27a0e5ac384e


    Awinish Vishwakarma - MVP - Directory Services

    My Blog: awinish.wordpress.com

    Disclaimer This posting is provided AS-IS with no warranties/guarantees and confers no rights.

    • Marked as answer by Bruce-Liu Wednesday, April 11, 2012 5:12 AM
    Monday, April 9, 2012 4:46 PM

All replies

  • You can use this logic - http://portal.sivarajan.com/2011/07/move-computer-objects-based-on.html

    dsquery * -limit 0 -filter
    "(&(ObjectClass=computer)(objectCategory=Computer))" -attr operatingSystemVersion
    name

    You can use the same LDAP filer in the ADUC.


    Santhosh Sivarajan | Houston, TX
    http://www.sivarajan.com/

    FaceBook Twitter LinkedIn SS Tech Forum

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

    Monday, April 9, 2012 2:38 PM
  • Please find the queries below.

    Query All OS:

    dsquery * -Filter "(&(objectClass=computer)(operatingSystem=*))" -limit 0 -Attr name operatingSystem

    Query Windows 7:

    dsquery * -filter "(&(&(sAMAccountType=805306369)(objectCategory=computer)(operatingSystemVersion=6*)(operatingSystem=Windows 7*)))" -limit 0 -attr name operatingsystem


    Query Windows XP:

    dsquery * -filter "(&(&(sAMAccountType=805306369)(objectCategory=computer)(operatingSystem=Windows XP*)))" -limit 0 -attr name operatingsystem


    Query Windows 2003:

    dsquery * -filter "(&(&(&(sAMAccountType=805306369)(objectCategory=computer)(operatingSystemVersion=5*)(operatingSystem=Windows Server*))))" -limit 0 -attr name operatingsystem


    Query Windows 2008:

    dsquery * -filter "(&(&(sAMAccountType=805306369)(objectCategory=computer)(operatingSystemVersion=6*)(operatingSystem=Windows Server*)))" -limit 0 -attr name operatingsystem

    Revert for any help.

    Sajeed AM


    Sajeed AM

    Monday, April 9, 2012 2:40 PM
  • Okay, walk me through step by step please on how to create and run these query's.

    Thanks,

    Monday, April 9, 2012 2:45 PM
  • Hello,

    I would agree with others.

    dsquery * commands is an option to go to get any wanted attribute.

    More about it: http://technet.microsoft.com/en-us/library/cc754232%28v=ws.10%29.aspx

    Operating System Version: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724832%28v=vs.85%29.aspx

    If you want to use such filter in a script, you can just add the fact that it will save the output in a file.

    For that, you can use the following (An update of Santhosh suggested command):

    dsquery * -limit 0 -filter "(&(ObjectClass=computer)(objectCategory=Computer))" -attr name operatingSystemVersion > c:\computers.txt

    The output of this command will be stored in a text file named computers.txt and will make easier reading the list.

    More about operating-system-version attribute: http://msdn.microsoft.com/en-us/library/windows/desktop/ms679079%28v=vs.85%29.aspx


    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 Monday, April 9, 2012 3:18 PM giving more info
    Monday, April 9, 2012 3:10 PM
  • Just run this DQUERY command from command line

    dsquery * -limit 0 -filter
    "(&(ObjectClass=computer)(objectCategory=Computer))" -attr operatingSystemVersion
    name



    Santhosh Sivarajan | Houston, TX
    http://www.sivarajan.com/

    FaceBook Twitter LinkedIn SS Tech Forum

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


    Monday, April 9, 2012 3:13 PM
  • your query doesn't work.


    Monday, April 9, 2012 3:17 PM
  • Copy and paste it like that:

    dsquery * -limit 0 -filter "(&(ObjectClass=computer)(objectCategory=Computer))" -attr operatingSystemVersion name

    The issue you had is due to the fact that the command was written on multiple lines and when you copy and paste, CMD tries to run each line as a separate command.

    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

    Monday, April 9, 2012 3:22 PM
  • Mr X, thanks that worked for running the command, but how do I get it to query and properly show the operating system versions.
    Monday, April 9, 2012 3:24 PM
  • You are not pasting all the commands in a single line.  It is a single line DSQUERY command.


    Santhosh Sivarajan | Houston, TX
    http://www.sivarajan.com/

    FaceBook Twitter LinkedIn SS Tech Forum

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

    Monday, April 9, 2012 3:51 PM
  • The command suggested does retrieve operatingSystemVersion, such as "6.1 (7600)". Perhaps you want to retrieve the operatingSystem attribute instead, which will be something similar to "Windows 7 Professional".


    Richard Mueller - MVP Directory Services

    Monday, April 9, 2012 3:54 PM
  • Still do not understand, I'm novice when it comes to this, i have also asked that you provide detailed instruction. I ran Mr X's query and that worked perfect but didn't show hostnames to windows version at all. Just showed Hostnames.
    Monday, April 9, 2012 3:54 PM
  • Hi again,

    Since you are novice, I would recommend creating a batch file (a file which extension is .bat) and then add the following command in this file:

    for /f "Tokens=*" %%s in ('dsquery computer -limit 0') do (
    for /f "Tokens=*" %%P in ('dsquery * %%s -attr name ^|find /V "name"') do (

    for /f "Tokens=*" %%Q in ('dsquery * %%s -attr operatingSystemVersion ^|find /V "operatingSystemVersion"') do (

    for /f "Tokens=*" %%R in ('dsquery * %%s -attr operatingSystem ^|find /V "operatingSystem"') do (

    echo %%P; %%Q ; %%R >> c:\allcomputers.CSV
    )
    )
    )
    )

    Once done, run the script and then you will find a file under c:\ named allcomputers.csv where you will find three columns if you open it using Excel:

    • Column 1: Name
    • Column 2: Operating System Version
    • Column 3: Operating System

    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 Monday, April 9, 2012 4:06 PM
    • Marked as answer by Chicojrman1 Monday, April 9, 2012 5:34 PM
    Monday, April 9, 2012 4:06 PM
  • Moreover, below scripts can be used too.

    http://gallery.technet.microsoft.com/scriptcenter/Display-computers-status-c8ff289d

    http://gallery.technet.microsoft.com/scriptcenter/c79e9809-b8e8-4cf1-af07-27a0e5ac384e


    Awinish Vishwakarma - MVP - Directory Services

    My Blog: awinish.wordpress.com

    Disclaimer This posting is provided AS-IS with no warranties/guarantees and confers no rights.

    • Marked as answer by Bruce-Liu Wednesday, April 11, 2012 5:12 AM
    Monday, April 9, 2012 4:46 PM
  • Please find the steps below.

    Step 1: Launch DSA.MSC

    Step 2: Select Custom search and go to Advanced

    Step 3: Past the query


    Sajeed AM|+919846553328

    Tuesday, April 10, 2012 9:28 AM