Skip navigation

JSI Tip 8273. How can I update all the blank computer descriptions in Active Directory with each computer's local description?

Using the Active Directory command-line tools and information from How do I know what attribute names to use when performing a 'DSQUERY *'?, I have scripted UpdCompDesc.bat to update every computer in Active Directory that has a blank (nul) description with the description that is set on the local computer.

UpdCompDesc.bat contains:

@echo off
setlocal
set q1=dsquery * domainroot -filter "(&(objectCategory=Computer)(objectClass=Computer))"
set q2=-attr name distinguishedName -Limit 0
for /f "Skip=1 Tokens=1*" %%a in ('%q1% %q2%') do (
 set name=%%a
 set dn="%%b"
 call :attr
)
endlocal
goto :EOF
:attr
set dn=%dn:  =%
set dn=%dn: "="%
set desc=""
for /f "Skip=1 Tokens=*" %%c in ('dsget computer %dn% -desc^|find /i /v "dsget succeeded"') do (
  if "%%c" NEQ "" set desc="%%c"
)
if %desc% NEQ "" goto :EOF
set dok=1
set desc=""
for /f "Skip=1 Tokens=*" %%v in ('net view \\%name%') do (
 set work=%%v
 call :view
)
if "%dok%" NEQ "3" goto :EOF
call :upd
goto :EOF
:view
if "%dok%" EQU "3" goto :EOF
if "%dok%" EQU "1" set desc="%work%"&set dok=2&goto :EOF
if "%dok%" NEQ "2" goto :EOF
if "%work:~0,11%" NEQ "Share name " goto :EOF
set dok=3
goto :EOF
:upd
set desc=%desc:  =%
set desc=%desc: "="%
@echo dsmod computer %dn% -desc %desc%
dsmod computer %dn% -desc %desc%



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish