0

I'm really new to the VBscripting world, so please be gentle :) I'm trying to display the OU of a computer on a network which has 2 domains. I have a script to display the details of the local computer:

Set objSysInfo = CreateObject("ADSystemInfo")
strComputerDN = objSysInfo.ComputerName
Set objComputer = GetObject("LDAP://" & strComputerDN)
Set objNetwork = CreateObject("Wscript.Network")
Wscript.Echo objComputer.distinguishedName

But I've had no luck with displaying the same for a computer name that I enter in an InputBox. Any help will be greatly appreciated.

Cheers

Alex
  • 8,827
  • 3
  • 42
  • 58
Ronnie S
  • 23
  • 1
  • 3

1 Answers1

0

You have to query AD for that name. My ADQuery class should get you around most of the boilerplate code required for this.

'<-- insert class code here

computer = ...

Set qry = New ADQuery
qry.Filter = "(&(objectCategory=computer)(sAMAccountName=" & computer & "$))"

Set obj = qry.Execute
Do Until obj.EOF
  WScript.Echo Split(obj("distinguishedName").Value, ",", 2)(1)
  obj.MoveNext
Loop
obj.Close
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • Thanks heaps for the reply!! will test it out and see if it works for me!! Cheers :) – Ronnie S May 02 '13 at 09:51
  • Hi! I tried your suggested script and I'm getting the error message Object required 'obj'. Am I doing something wrong? Thanks again – Ronnie S May 03 '13 at 07:58
  • If obj is `Nothing` (check with `WScript.Echo TypeName(obj)`) the query didn't find a matching object. Does the domain you're logged into actually have a matching computer object? – Ansgar Wiechers May 04 '13 at 23:16
  • Yes the computer is on the domain I tried with 5 different computers and I'm getting the same error. line 401 char 1, Object required 'obj'. Cheers – Ronnie S May 07 '13 at 10:21