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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1991
  • Last Modified:

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
0
Pollin
Asked:
Pollin
  • 2
1 Solution
 
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
0
 
PollinAuthor Commented:
Thanks Chris, You are a Star!!!!
0
 
Chris DentPowerShell DeveloperCommented:

Pleasure :)

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

Chris
0

Featured Post

Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

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