[Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 668
  • Last Modified:

Active Directory

Ok here is what I'm wanting to do. I would like to update the computer description filed in Active Directory.  I have close to 200 PC's so I really would like an automated way.

I can do a Net View and it shows all the correct information on the computer description filed of the PC.  Now is there away to get that information into AD automatically maybe via a script or something?
  • 3
  • 3
  • 2
2 Solutions
karmstrongAuthor Commented:
I found this Bat file which should do the trick however I get an erorr any idea?

@echo off
set Machine=%1
set Description=%2
for /f "delims=" %%a in ('dsquery computer -name "%Machine%"') do set MachineDN=%%a
dsmod computer %MachineDN% -desc %Description%

dsquery failed:The search filter cannot be recognized.
type dsquery /? for help.dsmod failed:No value specified for `desc'.
type dsmod /? for help.
The above script will need two arguments when run, first the computer name and then the description (in quotation marks).
Try this: on a Server 2003 or an XP workstation with adminpak.msi installed (for the ds-tools), open a command prompt and enter
net view >Description.txt
This will create a text file with the computer names and their description; open it in notepad and remove the unnecessary first lines. Remove as well any lines you don't want processed (you can leave lines with empty description, those won't be processed).
Then save and run this script in the same directory as the Description.txt.

@echo off
setlocal enabledelayedexpansion
set DescFile=%~dp0Description.txt

for /f "tokens=1*" %%a in ('type "%DescFile%"') do (
  set Machine=%%a
  set TempDesc=%%b
  call :process
goto leave

set Machine=%Machine:\=%
set Desc=
for %%a in (%TempDesc%) do set Desc=!Desc! %%a
if "%Desc%"=="" goto :eof
set Desc=%Desc:~1%
echo Processing %Machine%: %Desc%
dsquery computer domainroot -samid "%Machine%$" | dsmod computer -desc "%Desc%"
goto :eof

karmstrongAuthor Commented:
I get the fallowing message

| was unexpected at this time.
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Do you have special characters in your descriptions, like | < > ^ & % or quotation marks?
karmstrongAuthor Commented:
Yep sure did
worked Perfect thanks

One last question KNow of a script to clean out old computer names no longer used in AD?
You can do that with dsquery.exe:
dsquery computer domainroot -limit 0 -inactive <number of weeks>
will give a list of computers that haven't logged on in <number of weeks> weeks.
Yep, and pipe it to DSRM.


Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now