Solved

VBS Organisation Units

Posted on 2004-10-04
2
140 Views
Last Modified: 2010-05-02
Hi there,

I was wondering if anyone knows the script i need for a case statement depending on what OU a 'machine' is in, in my AD.

I have a VBS script that maps the printer but i need a new script for every printer the company has. So what i want is a script to do the following:

Ask what OU the local machine is in
Case in OU 'Group 1' map Printer1
Case in OU 'Group 2' map printer 2
....and so on.

So what i really need is the case statement and details on how it would identify what OU a machie is in.

Thanks very much.
0
Comment
Question by:clivecrawdevil
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Accepted Solution

by:
domj earned 250 total points
ID: 12221379
This should work for you:

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dim ArgObj
Dim objEnv ' as collection
Dim objUser 'As IADsUser
Dim objMailbox 'As CDOEXM.IMailboxStore
Dim sUserLDAPName 'As String
Dim DCServer 'As String

 

' Get the Arguments object
Set ArgObj = WScript.Arguments

 

If ArgObj.Count < 1 Then
   Set WNetwork = CreateObject("WScript.Network")
      strComp=WNetwork.ComputerName

else
   strComp = UCase(ArgObj(0))
End If

sCompLDAPName = QueryActiveDirectory()

Select Case True
Case Instr(sCompLDAPName,"ou={InsertOUtoCompare}")>0
      'Action to complete if true
Case Instr(sCompLDAPName,"ou={InsertOUtoCompare}")>0
      'Action to complete if true
Case Else
      'Action to complete if none are true
End Select


Public Function QueryActiveDirectory()

set fso=CreateObject("Scripting.FileSystemObject")
set fsoFile=fso.CreateTextFile("C:\export.csv",True)
 
    Dim oAD 'As IADs
    Dim oGlobalCatalog 'As IADs
    Dim oRecordSet 'As Recordset
    Dim oConnection 'As New Connection
    Dim strADsPath 'As String
    Dim strQuery 'As String
    Dim strUPN 'As String

 

    set oRecordSet = CreateObject("ADODB.Recordset")
    set oConnection = CreateObject("ADODB.Connection")

 

    'Determine the global catalog path
    Set oAD = GetObject("GC:")
    For Each oGlobalCatalog In oAD
        strADsPath = oGlobalCatalog.AdsPath
    Next
    'Initialize the ADO object
    oConnection.Provider = "ADsDSOObject"
    'The ADSI OLE-DB provider
    oConnection.Open "ADs Provider"
    'Create the search string
    strQuery = "<" & strADsPath & _
      ">;(&(objectCategory=computer)(cn=" & strComp & "));cn,distinguishedName,mail;subtree"  
        'Execute the query

    Set oRecordSet = oConnection.Execute(strQuery)
    If oRecordSet.EOF And oRecordSet.BOF Then    
       'An empty recordset was returned
      msgBox "No records found"
    Else    'Records were found; loop through them
        While Not oRecordSet.EOF
            QueryActiveDirectory = oRecordSet.Fields("distinguishedName")
            oRecordSet.MoveNext
        Wend
    End If
End Function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Dom
0
 

Author Comment

by:clivecrawdevil
ID: 12309562
Thanks very much
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question