Jump to content

Recommended Posts

Posted

I'm sure I saw an example VB script here somewhere with the code for mapping drives by user OU location, I currently do this by group membership but could do with an option to map by OU.

 

Can anyone point me to a thread?

 

Thanks.

Posted

You may find the following functions of use;

 

These simply work by using the ADSystemInfo object which can return the AD path of the user or computer account in the form CN=user,OU=students,OU=users,DC=domain,DC=root. It's then a simple InStr to see if whatever is sent as a parameter appears somewhere in the string. This does mean that you have to be a bit careful with the parameter as asking for a match with 'Students' would return a positive if the OU 'NonStudents' was somewhere in the path!! Easiest to use a parameter in the form 'OU=full OU name,'

 

' Check if user is member of an Organisational Unit
Function UserInOU(sOU)
' Returns true if the user is a member of the specified OU (or descendant)
Dim oAdSys, sUserDN
Set oAdSys = CreateObject("ADSystemInfo")
sUserDN = UCase(oAdSys.UserName)
UserInOU = (InStr(1, sUserDN, UCase(sOU)) > 0)
End function

' Check if Computer is a member of an Organisational Unit
Function ComputerInOU(sOU)
  ' Returns true if the computer is a member of the specified OU (or descendant)
  Dim oAdSys, sComputerDN
  Set oAdSys = CreateObject("ADSystemInfo")
  sComputerDN = UCase(oAdSys.ComputerName)
  ComputerInOU = (InStr(1, sComputerDN, UCase(sOU)) > 0)
End Function

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...