Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


AD to Access

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,42182
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> AD to Access
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1] 2   next >   >>
Login
Message << Older Topic   Newer Topic >>
 AD to Access - 1/18/2007 5:58:24 AM   
  twilliamsen

 

Posts: 208
Score: 0
Joined: 1/18/2007
Status: offline
I am trying to create an inventory database by querying the AD through ADO.  I am attempting to grab the computer names from Active Directory and use those names to create an Inventory of the computers and their hardware

I have commeted some of the items out because I get errors with them but have not chose to remove them yet.

Here is my code:


      
 
 
Post #: 1
 
 RE: AD to Access - 1/18/2007 6:23:34 AM   
  dm_4ever


Posts: 2722
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
Is all the info you're collecting going into one table?

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to twilliamsen)
 
 
Post #: 2
 
 RE: AD to Access - 1/18/2007 6:29:57 AM   
  twilliamsen

 

Posts: 208
Score: 0
Joined: 1/18/2007
Status: offline
Yes for now.  That is the easy part. 

(in reply to dm_4ever)
 
 
Post #: 3
 
 RE: AD to Access - 1/18/2007 6:35:56 AM   
  dm_4ever


Posts: 2722
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
If it's going into one table, then your code should look more like this:
One objRecordset.AddNew and objRecordset.Update per machine.  You may want to put some error handling in there as well since there may be some machines that you will not be able to connect to via WMI due to permission issues or WMI related problems.


      

< Message edited by dm_4ever -- 1/18/2007 6:42:47 AM >


_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to twilliamsen)
 
 
Post #: 4
 
 RE: AD to Access - 1/18/2007 6:46:58 AM   
  twilliamsen

 

Posts: 208
Score: 0
Joined: 1/18/2007
Status: offline
Thanks for the code change, but I am getting an error on line 52

It doesn't like this

Set objWMIService = GetObject("winmgmts:\\" & strComputers & "\root\cimv2")

Which maybe a problem with this:


strComputers = objRecordsetAD.Fields("Name").Value

 
I get the following error: 
 
Line 52
The remote server machine does not exist or is unavailable: 'GetObject'




< Message edited by twilliamsen -- 1/18/2007 6:49:38 AM >

(in reply to dm_4ever)
 
 
Post #: 5
 
 RE: AD to Access - 1/18/2007 7:03:58 AM   
  dm_4ever


Posts: 2722
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
That probably has to do with what I told you to look out for. There may be some machine's you can't connect to (turned off, not enough permissions, WMI is broken, etc.).  Have you verified strComputers = objRecordsetAD.Fields("Name").Value  is providing a computername?

I don't think you need this either since you're querying AD:
Dim oContainer

'Initialize global variables

Set oContainer=GetObject("LDAP://cn=Computers,DC=corp-nj,DC=mrsassociates,dc=com ")

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to twilliamsen)
 
 
Post #: 6
 
 RE: AD to Access - 1/18/2007 7:08:00 AM   
  twilliamsen

 

Posts: 208
Score: 0
Joined: 1/18/2007
Status: offline
I know it works from when I queried it using that code to dump into a textfile.  The computers are to left on all the time.  It is company policy, but that doesn't mean they follow it. 


Here is the code for dumping the computer names into a textfile


      

< Message edited by twilliamsen -- 1/18/2007 7:09:55 AM >

(in reply to dm_4ever)
 
 
Post #: 7
 
 RE: AD to Access - 1/18/2007 7:19:17 AM   
  dm_4ever


Posts: 2722
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
You mentioned it yourself, the error is with this line:  Set objWMIService = GetObject("winmgmts:\\" & strComputers & "\root\cimv2")  which means you're querying AD just fine, but having issues connecting via WMI to the machine.  The piece below may help get over the problem computer, but you may want to think of a better method to handle errors.  Perhaps add logging for machine's you're unable to connect via WMI for whatever reason.

Do Until objRecordSetAD.EOF
   ' ==================================================================================================
   ' Grabs Computer Name, Manufacturer, Model, and Installed Ram from the ComputerSystem WMI Service
   '===================================================================================================
  
   strComputers = objRecordsetAD("Name")
   On Error Resume Next
   Set objWMIService = GetObject("winmgmts:\\" & strComputer& "\root\cimv2")
   If Err.Number <> 0 Then 'if you get an error trying to connect then move to the next computer
       On Error GoTo 0
       objRecordsetAD.MoveNext
   End If
   objRecordset.AddNew

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to twilliamsen)
 
 
Post #: 8
 
 RE: AD to Access - 1/18/2007 7:25:47 AM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: online
I would add this just to be on the safe side:

  strComputers = objRecordsetAD("Name")
  On Error Resume Next
  Set objWMIService = GetObject("winmgmts:\\" & strComputer& "\root\cimv2")
  If Err.Number <> 0 Then 'if you get an error trying to connect then move to the next computer
      On Error GoTo 0
      objRecordsetAD.MoveNext
  End If
  On Error Goto 0
  objRecordset.AddNew

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to dm_4ever)
 
 
Post #: 9
 
 RE: AD to Access - 1/18/2007 7:41:39 AM   
  twilliamsen

 

Posts: 208
Score: 0
Joined: 1/18/2007
Status: offline
Still isn't working properly.  Maybe I should go back to a text file, then delete the file after words. 

(in reply to dm_4ever)
 
 
Post #: 10
 
 RE: AD to Access - 1/18/2007 7:53:12 AM   
  twilliamsen

 

Posts: 208
Score: 0
Joined: 1/18/2007
Status: offline
quote:

ORIGINAL: ebgreen

I would add this just to be on the safe side:

strComputers = objRecordsetAD("Name")
On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer& "\root\cimv2")
If Err.Number <> 0 Then 'if you get an error trying to connect then move to the next computer
    On Error GoTo 0
    objRecordsetAD.MoveNext
End If
On Error Goto 0
objRecordset.AddNew


With this I get an error of Object Required: 'objWMIService'

Line 49
char: 1

Which is this line


Set
colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem")

(in reply to ebgreen)
 
 
Post #: 11
 
 RE: AD to Access - 1/18/2007 7:58:00 AM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: online
Where do you instantiate the objWMIService object?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to twilliamsen)
 
 
Post #: 12
 
 RE: AD to Access - 1/18/2007 8:00:28 AM   
  twilliamsen

 

Posts: 208
Score: 0
Joined: 1/18/2007
Status: offline
right here


strComputer = objRecordsetAD("Name")
On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer& "\root\cimv2")  <------ initiates here

If
Err.Number <> 0 Then 'if you get an error trying to connect then move to the next computer      

On
Error GoTo 0
objRecordsetAD.MoveNext

End
If
On
Error Goto 0
objRecordset.AddNew

Set
colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem")
For Each objItem in colItems
objRecordset("ComputerName") = objItem.Name
objRecordset("Manufacturer") = objItem.Manufacturer
objRecordset("Model") = objItem.Model
objRecordset("Installed Ram") = objItem.TotalPhysicalMemory
objRecordset("CPU Count") = objItem.NumberofProcessors
Next

(in reply to ebgreen)
 
 
Post #: 13
 
 RE: AD to Access - 1/18/2007 8:04:38 AM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: online
So if you cannot connect to strComputer, then you won't be able to instantiate the object. Your logic needs to reflect that.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to twilliamsen)
 
 
Post #: 14
 
 RE: AD to Access - 1/18/2007 8:06:44 AM   
  twilliamsen

 

Posts: 208
Score: 0
Joined: 1/18/2007
Status: offline
To test it should I run a test on it to see if I can dump the AD computers into a text file and compare the text file to the AD and then see if I can connect to that PC?

(in reply to ebgreen)
 
 
Post #: 15
 
 RE: AD to Access - 1/18/2007 10:56:21 AM   
  dm_4ever


Posts: 2722
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
How about this?  I just put the piece where you query WMI and insert into a DB into a function.  Should make testing an individual machine easier.

      

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to twilliamsen)
 
 
Post #: 16
 
 RE: AD to Access - 1/19/2007 1:35:36 AM   
  twilliamsen

 

Posts: 208
Score: 0
Joined: 1/18/2007
Status: offline
Very interesting.  I must of burned myself out, why didn't I think of that?  Let me give it a whirl and see what happens!  I will let you know the result!

(in reply to dm_4ever)
 
 
Post #: 17
 
 RE: AD to Access - 1/19/2007 2:24:01 AM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: online
I would still suggest putting an On Error Goto 0 outside the If-End If block.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to twilliamsen)
 
 
Post #: 18
 
 RE: AD to Access - 1/19/2007 2:38:40 AM   
  dm_4ever


Posts: 2722
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
Good point ...especially while trying to find and work out any kinks.

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ebgreen)