FileName: Querycomputer.bat
Features: Finds computers that are not grouped within a domain and displays the computer name and user with domain
Role: You can implement a list of monitoring computers to remind computer groupings, but also to audit the computer naming norms, determine the responsible person.
Note: Before a batch is run, it is a good idea to group all computers in the computers container within an existing domain by an OU, and the script will list the new computers in the Computers container after it runs.
Copy Code code as follows:
@echo off
No grouped computer monitoring in echo domain
echo If you find a computer, it displays a list of the computers found and prompts you with a PC horn.
Echo.
CD/D%~dp0
REM Setting NetBIOS domain name
Set Domain=domainname
REM Set domain name
Set Dc=mydomain
Set dc1=com
: Loop
Set Found=0
REM Search for Vegetarian comouters
for/f%%i in (' dsquery computer cn^=computers^,dc^=%dc%^,dc^=%dc1% ') do set found=1
rem If you find a computer, call the display module
If%found%==1 call:d isplay
Ping-n 127.0.0.1 >nul 2>&1
Goto Loop
Goto:eof
:d Isplay
echo%date%%time% found following computers:
REM reads the computer ad path and invokes 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%.%d C1%/%dsname: "=%
REM Get computer name
for/f "tokens=2,3* delims=,="%%i in (' echo%dsname% ') do set name=%%i
REM Displays computer permissions and displays permissions to set DNS information for users (plus domain), dscals need to install support Tools
DSACLS%dsname1% |find "%domain%" |find "DNS" >name.txt
for/f "tokens=1,2,3*"%%i in (name.txt) do set user=%%j
Echo%name%,%user%
REM Record information
echo%name%,%user%>> "%date%.csv"
rem beep Alarm, beep write yourself or go online to find
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