Genius / Masochist tag? gimme, gimme, gimme!
Easy really. The functions below will tell you if your logged on user or computer are in (or below) an OU. Actually what they do is search the LDAP string (LDAP://CN=object,OU=container,OU=container,DC=mydomain,DC =com) for whatever you send in the sOU parameter. To be on the safe side, you should specify the OU like this 'OU=ouname,' including the trailing comma.
I'm sure there are more elegant or clever ways to do this but these work for me.
Code:
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
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