JSI Tip 8305. How can I set the computer description in Active Directory equal to the logged on UserName?
Jerold Schulman
July 28, 2004
1 Min Read
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 SetCDName.bat to set the computer description in Active Directory equal to the logged on UserName.
The syntax for using SetCDName.bat is:
SetCDName [NONE]
Where NONE prevents prefixing the UserName with User=.
NOTE: Descriptions that already begin with User= are not updated, allowing you to run SetCDName.bat several times, to insure you get all descriptions updated.
NOTE: SetCDName.bat uses WhoConsole.bat and WhoConsole.vbs.
SetCDName.bat contains:
@echo offsetlocalset prefix=User=if /i {%1}=={NONE} set prefix=%1set q1=dsquery * domainroot -filter "(&(objectCategory=Computer)(objectClass=Computer))"set q2=-attr distinguishedName name description -L -Limit 0set /a cnt=0for /f "Tokens=1* Delims=:" %%a in ('%q1% %q2%') do ( set p1=%%a set p2=%%b call :attr)endlocalgoto :EOF:attrset /a cnt=%cnt% + 1if /i "%p1%" EQU "name" set name=%p2:~1%&goto t3if /i "%p1%" EQU "description" set desc=%p2:~1%&goto t3if /i "%p1%" EQU "distinguishedName" set dn=%p2:~1%:t3if %cnt% EQU 3 call :chkdescgoto :EOF:chkdescset /a cnt=0if "%desc%" EQU "" goto whoif /i "%prefix%" EQU "NONE" goto whoif "%desc:~0,5%" EQU "%prefix%" goto :EOF:whocall WhoConsole.bat %name% userif "%user%" EQU "null" goto :EOFif /i "%prefix%" EQU "NONE" set desc=%user%&goto updateset desc=%prefix%%user%:updatedsmod computer "%dn%" -desc "%desc%"
About the Author
Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.
You May Also Like