|
server
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Applying user settings based on computer location
We need to set a default printer for users on particular computers in
which these computers are all in a particular OU in Active Directory. It seems the best way to do this is to read the computer name in the script and then enumerate the OU to read the computer account names and compare them. Is there another way of doing this otherwise what is the script needed to read the computer account names out of an OU? SchoolTech wrote:
> We need to set a default printer for users on particular computers in If you want to determine the OU/Container the computer object resides in, > which these computers are all in a particular OU in Active Directory. > > It seems the best way to do this is to read the computer name in the > script and then enumerate the OU to read the computer account names and > compare them. > > Is there another way of doing this otherwise what is the script needed to > read the computer account names out of an OU? you can parse the Distinguished Name (DN) of the computer for this. Or, you can bind to the computer object and use the Parent method to find the AdsPath of the parent container/OU. If the client is at least Windows 2000, you can use the ADSystemInfo object. For example: ' Retrieve DN of local computer. Set objSysInfo = CreateObject("ADSystemInfo") strComputerDN = objSysInfo.ComputerName ' Bind to computer object. Set objComputer = GetObject("LDAP://" & strComputerDN) ' Bind to Parent object. Set objParent = GetObject(objComputer.Parent) If (objParent.Name = "ou=Sales") Then ' Computer is in ou=Sales. End If If (objParent.distinguishedName = "ou=Sales,ou=West,dc=MyDomain,dc=com") Then ' Computer is in another OU called sales. End If Richard Mueller [MVP] wrote:
Show quote > SchoolTech wrote: I think the problem with using DNs is case sensitivity and spaces could > >> We need to set a default printer for users on particular computers in >> which these computers are all in a particular OU in Active Directory. >> >> It seems the best way to do this is to read the computer name in the >> script and then enumerate the OU to read the computer account names and >> compare them. >> >> Is there another way of doing this otherwise what is the script needed to >> read the computer account names out of an OU? > > If you want to determine the OU/Container the computer object resides in, > you can parse the Distinguished Name (DN) of the computer for this. Or, you > can bind to the computer object and use the Parent method to find the > AdsPath of the parent container/OU. If the client is at least Windows 2000, > you can use the ADSystemInfo object. For example: > > ' Retrieve DN of local computer. > Set objSysInfo = CreateObject("ADSystemInfo") > strComputerDN = objSysInfo.ComputerName > > ' Bind to computer object. > Set objComputer = GetObject("LDAP://" & strComputerDN) > > ' Bind to Parent object. > Set objParent = GetObject(objComputer.Parent) > > If (objParent.Name = "ou=Sales") Then > ' Computer is in ou=Sales. > End If > If (objParent.distinguishedName = "ou=Sales,ou=West,dc=MyDomain,dc=com") > Then > ' Computer is in another OU called sales. > End If > be an issue. Normally when writing out a DN spaces might be inserted, which generally are ignored. Can it be guaranteed no spaces are returned except in object names e.g. ou=My OU, [...] I want to find out if the OU is a child of the path "ou=OU1, ou=OU2, ou=OU3, dc=MyDomain, dc=com" etc, as the name of the OU they are in is not necessarily unique in the entire directory, only in the tree it is in. SchoolTech wrote:
Show quote > Richard Mueller [MVP] wrote: Looking at something like>> SchoolTech wrote: >> >>> We need to set a default printer for users on particular computers in >>> which these computers are all in a particular OU in Active Directory. >>> >>> It seems the best way to do this is to read the computer name in the >>> script and then enumerate the OU to read the computer account names >>> and compare them. >>> >>> Is there another way of doing this otherwise what is the script >>> needed to read the computer account names out of an OU? >> >> If you want to determine the OU/Container the computer object resides >> in, you can parse the Distinguished Name (DN) of the computer for >> this. Or, you can bind to the computer object and use the Parent >> method to find the AdsPath of the parent container/OU. If the client >> is at least Windows 2000, you can use the ADSystemInfo object. For >> example: >> >> ' Retrieve DN of local computer. >> Set objSysInfo = CreateObject("ADSystemInfo") >> strComputerDN = objSysInfo.ComputerName >> >> ' Bind to computer object. >> Set objComputer = GetObject("LDAP://" & strComputerDN) >> >> ' Bind to Parent object. >> Set objParent = GetObject(objComputer.Parent) >> >> If (objParent.Name = "ou=Sales") Then >> ' Computer is in ou=Sales. >> End If >> If (objParent.distinguishedName = >> "ou=Sales,ou=West,dc=MyDomain,dc=com") Then >> ' Computer is in another OU called sales. >> End If >> > > I think the problem with using DNs is case sensitivity and spaces could > be an issue. Normally when writing out a DN spaces might be inserted, > which generally are ignored. Can it be guaranteed no spaces are returned > except in object names e.g. ou=My OU, [...] > > I want to find out if the OU is a child of the path "ou=OU1, ou=OU2, > ou=OU3, dc=MyDomain, dc=com" etc, as the name of the OU they are in is > not necessarily unique in the entire directory, only in the tree it is in. 'Paths 'Hillview/Pupils/Senior/Suite 'Hillview/Pupils/Senior/Classrooms 'Hillview/Pupils/Junior/Classrooms 'Try to identify where we are Dim objADPath, objMe, objSysInfo, sRoot, oRoot strADPath = "ou=Suite ,ou=Senior, ou=Pupils, ou=Hillview" Set oRoot = GetObject("LDAP://rootDSE") sRoot = oRoot.Get("defaultNamingContext") ' Retrieve DN of local computer. Set objSysInfo = CreateObject("ADSystemInfo") strComputerDN = objSysInfo.ComputerName ' Bind to computer object. Set objComputer = GetObject("LDAP://" & strComputerDN) ' Bind to Parent object. Set objParent = GetObject(objComputer.Parent) Set objADPath = GetObject ("LDAP:// " & strADPath & ", " & sRoot) If objParent.distinguishedName = objADPath.distinguishedName Then ' Computer is in our place WScript.echo "InPath=" & objParent.distinguishedName Else WScript.echo "OutPath=" & objParent.distinguishedName End If But you know that string comparisons are to be avoided if possible... case sensitivity and spaces and all that :) |
|||||||||||||||||||||||