Partager via


Using script with AD database

Courtesy: Nguyen Quoc Dung.

Use these scripts if you want to list and execute all AD objects that are inactive for more than 60 days and count all Computers in AD grouped by OS, so you can know how many percentages of computers running XP or Windows 7. These information is extracted from AD Database and write a statistical report to a text file.

How to use it:

- Script file download (Use it at your own risk): ListComputers.jse

- Run it in computer joined domain and under domain account, just by double click on it (if you want get default information: Count computers in current domain).

- For optional, I have only some more arguments, with syntax like: ListComputers.jse -forest [-domain:domainname] -detail

- Example: ListComputers.jse - forest

This will list all domains in forest and count computers for each domain

  • ListComputers.jse - domain: contoso.com

This will count computers in domain contoso.com

ListComputers.jse - detail

This will count computers in current domain and list all computer name with the obsoleted days, see the below result as an example.

  • You can use args -detail with -domain:domainname or with -forest. Don’t use -domain and -forest at the same time.
  • If you put wrong args, script will run as no args (same thing like you double click to file)

- Result is a file name like [ScriptName]_[Day]_[Month]_[Year].log in the same folder of this script.

======================= Sample script result

Script start at: Tue Feb 28 22:20:18 UTC+0700 2012
List of domain(s) in forest:
Contoso.com

List of Operating System in domain Contoso.com (Total=21):
Windows Server 2008 R2 Enterprise: 13 (Obsoleted: 10)
Windows Server 2008 R2 Standard: 1 (Obsoleted: 0)
Windows XP Professional: 1 (Obsoleted: 1)
Windows Server 2003: 3 (Obsoleted: 2)
Windows 7 Enterprise: 1 (Obsoleted: 1)
Windows 7 Professional: 2 (Obsoleted: 2)

List of computers by Operating System:

 - Windows Server 2008 R2 Enterprise (13):
    CN=DC02,OU=Machines,DC=Contoso,DC=com (Obsoleted 148 days)
    CN=EX2010,OU=Machines,DC=Contoso,DC=com (Obsoleted 78 days)
    CN=CON-SCCM-DW,OU=Machines,DC=Contoso,DC=com (Obsoleted 175 days)
    CN=CON-SCOM,OU=Machines,DC=Contoso,DC=com (Obsoleted 214 days)
    CN=CON-HOST-LAB,OU=Machines,DC=Contoso,DC=com (Obsoleted 148 days)
    CN=CON-MOSS1,OU=Machines,DC=Contoso,DC=com (Obsoleted 243 days)
    CN=CON-MOSS2,OU=Machines,DC=Contoso,DC=com (Obsoleted 204 days)
    CN=SCORCH2012,OU=Machines,DC=Contoso,DC=com
    CN=SCSM2012,OU=Machines,DC=Contoso,DC=com
    CN=SMSP,OU=Machines,DC=Contoso,DC=com (Obsoleted 174 days)
    CN=SCCMOM2012,OU=Machines,DC=Contoso,DC=com (Obsoleted 64 days)
    CN=CON-HYPERV-SRV,OU=Machines,DC=Contoso,DC=com (Obsoleted 79 days)
    CN=CON-SHAREPOINT,OU=Machines,DC=Contoso,DC=com

 - Windows Server 2008 R2 Standard (1):
    CN=DC01,OU=Domain Controllers,DC=Contoso,DC=com

 - Windows XP Professional (1):
    CN=CLIENT01,OU=Machines,DC=Contoso,DC=com (Obsoleted 467 days)

 - Windows Server 2003 (3):
    CN=EX2007,OU=Machines,DC=Contoso,DC=com (Obsoleted 463 days)
    CN=REMOTE,OU=Machines,DC=Contoso,DC=com
    CN=CON-OPALIS,OU=Machines,DC=Contoso,DC=com (Obsoleted 125 days)

 - Windows 7 Enterprise (1):
    CN=V-VHN9,OU=Machines,DC=Contoso,DC=com (Obsoleted 148 days)

 - Windows 7 Professional (2):
    CN=CON-WIN7-01,OU=Machines,DC=Contoso,DC=com (Obsoleted 134 days)
    CN=CON-WIN7-02,OU=Machines,DC=Contoso,DC=com (Obsoleted 99 days)

Script end at: Tue Feb 28 22:20:18 UTC+0700 2012. Running time: 1 seconds
Written by Nguyen Quoc Dung (dungnq@me.com)