?
Solved

VBS Organisation Units

Posted on 2004-10-04
2
Medium Priority
?
142 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 1000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month14 days, 10 hours left to enroll

770 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