COMPUTER DESCRIPTION WMI SCRIPT

Hello:

I have like 5000 computers in my active directory and I need to put on the computer description (in active directory) the logged user and the computer model. I know that there is a WMI script that allow to do this but dunno how to make it.

I have a .BAT script that updates the user name but I think that in order to use it I need to use .vsb script.

this is the script I have

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

I am giving 500 points as I need to do this assap or my boss is gonna kill me. Thanks
PollinAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris DentPowerShell DeveloperCommented:

Could you just check these are the bits you're after from the PC (will run for your local machine at the moment)? It just echos out the Model and User that's logged on. All in VbScript (.vbs).

Const WBEM_RETURN_IMMEDIATELY = &H10
Const WBEM_FORWARD_ONLY = &H20

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")

Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", _
            WBEM_RETURN_IMMEDIATELY + WBEM_FORWARD_ONLY)

For Each objItem in colItems
      WScript.Echo objItem.Model
      WScript.Echo objItem.UserName
Next
Set colItems = Nothing

If that is what you're after then it's quite simple to wrap everything else in so this updates the computer description. It will require a bit of checking to make sure it updates correctly.

Chris

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PollinAuthor Commented:
Thanks Chris, You are a Star!!!!
Chris DentPowerShell DeveloperCommented:

Pleasure :)

I take it you'll have no problems getting it to write back to the computer account from there?

Chris
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2003

From novice to tech pro — start learning today.