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

x
  • 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?
0
karmstrong
Asked:
karmstrong
  • 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
setlocal
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.
0
 
oBdACommented:
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.

====8<----[Description.cmd]----
@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

:process
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

:leave
====8<----[Description.cmd]----
0
 
karmstrongAuthor Commented:
I get the fallowing message

| was unexpected at this time.
0
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.

 
oBdACommented:
Do you have special characters in your descriptions, like | < > ^ & % or quotation marks?
0
 
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?
0
 
oBdACommented:
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.
0
 
Netman66Commented:
Yep, and pipe it to DSRM.

0

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