(Fresh Scripter)
2009-10-26 06:05 PM
Query Computer OU

Looking for a script to query what OU a computer is part of. Basically, want to write a script that says if a user is logging into a computer that belongs to the 'lab' OU, they will get blah blah blah. Is this possible?


Glenn BarnasAdministrator
(KiX Supporter)
2009-10-26 06:37 PM
Re: Query Computer OU

GetObjectOU() will do this - it's available from the Resources / Kix Function Library page on my web site.

It can return the DN string for a User or Computer. You can then do an InStr() to determine if the desired OU is in the DN string.


(KiX Supporter)
2009-10-26 06:48 PM
Re: Query Computer OU

This is one too: GetUserDN() -

There are a couple of different variations... look here: UDF Forum -

Richard H.Administrator
(KiX Supporter)
2009-10-27 08:43 AM
Re: Query Computer OU

Or just rip it straight out of ADSystemInfo.
Break ON

$objSysInfo = CreateObject("ADSystemInfo") 
$strComputerDN = $objSysInfo.computerName 
$strUserDN = $objSysInfo.userName 



"Information from ADSystemInfo"+@CRLF
"           User DN: "+$strUserDN+@CRLF
"    User container: "+$strUserOU+@CRLF
"       Computer DN: "+$strComputerDN+@CRLF
"Computer container: "+$strComputerOU+@CRLF

Exit 0

(Fresh Scripter)
2009-10-28 09:13 PM
Re: Query Computer OU

Hey all, didn't realize this thread got moved. Just saw the responses. Give me a day to reply back so I can play around with the responses I got. Thanks all.