File Name: querycomputer. bat
Function: finds ungrouped computers in the domain and displays the computer name and users in the domain.
Purpose: monitor the computer list to remind you to group computers. You can also check whether the computer naming rules are correct and determine the owner.
Note: Before batch processing, you are advised to group all the computers in the computers container in the existing domain by OU. After the script is run, the new computers in the computers container will be listed.
Copy codeThe Code is as follows: @ echo off
Ungrouped computers in the echo domain Monitor
Echo if a computer is found, a list of computers is displayed, and a prompt is displayed through the PC speaker.
Echo.
Cd/d % ~ Dp0
Rem sets NETBIOS Domain Name
Set domain = DOMAINNAME
Rem set Domain Name
Set DC = mydomain
Set DC1 = com
: Loop
Set found = 0
Rem search comouters
For/f % I in ('dsquery computer CN ^ = Computers ^, DC ^ = % DC % ^, DC ^ = % DC1 % ') do set found = 1
Rem calls the display module if a computer is found.
If % found % = 1 call: display
Ping-n 600 127.0.0.1> NUL 2> & 1
Goto loop
Goto: eof
: Display
Echo % date % time % found following computers:
Rem reads the computer's AD path and calls the display information module
For/f % I in ('dsquery computer CN ^ = computers ^, dc ^ = % DC % ^, dc ^ = % DC1 % ') do call: info % I
Goto: eof
: Info
Set dsname = % 1
Set dsname1 = // % DC %. % DC1 %/% dsname: "= %
Rem obtains the computer name
For/f "tokens = 2, 3 * delims =, =" % I in ('echo % dsname % ') do set name = % I
Rem displays the computer permissions and the users who can set DNS information (persons with Domain Names). dscals needs to install Support Tools
Dsacls % dsname1 % | find "% domain %" | find "DNS"> name.txt 2> & 1
For/f "tokens = 1, 2, 3 *" % I in (name.txt) do set user = % j
Echo % name %, % user %
Rem record information
Echo % name %, % user %> "paidate0000.csv"
Rem beep alert, which is written by beep or found on the Internet
Echo.
Beep 1500 500
Beep 500 500
Beep 1500 500
Beep 500 500
Beep 1500 500
Beep 500 500
Beep 1500 500
Beep 500 500
Goto: eof