#186573 - 2008-03-31 05:43 PM
Find OU of PC
|
Mike1982
Fresh Scripter
Registered: 2007-06-15
Posts: 6
|
Not familiar with LDAP so I am having trouble trying to figure out how to do this. What I need to do is given a pc name, query AD to find out the OU that the pc belongs to. I found a script that works when I run it from the pc, but not from the server.
|
|
Top
|
|
|
|
#186575 - 2008-03-31 06:51 PM
Re: Find OU of PC
[Re: Mike1982]
|
kholm
Korg Regular
   
Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
|
Try the Function TranslateName in the UDF library
TranslateName
-Erik
|
|
Top
|
|
|
|
#186577 - 2008-03-31 08:06 PM
Re: Find OU of PC
[Re: kholm]
|
Mike1982
Fresh Scripter
Registered: 2007-06-15
Posts: 6
|
I tried that, but it didn't work. I have the following AD structure.
We have domain computers with contains under that for each of our locations. I can get it to work if I put in "domain computers", but I need to match up against the location under that level. EX. I have a location container called Austin under domain computers. I need to match compare it against "Austin"
|
|
Top
|
|
|
|
#186641 - 2008-04-02 03:44 PM
Re: Find OU of PC
[Re: Les]
|
Mike1982
Fresh Scripter
Registered: 2007-06-15
Posts: 6
|
What I want to do is supply a pc name and query AD to find out the OU that it is in. I can get it to work fine when running from the machine itself. What I want to to is run it from the server. I want to supply a pc name, and have it give me the OU that is in and from there take some action. The problem I'm having is we have the following AD structure. "Domain Computers" and under there we have OU's by location name, such as Austin, Riverside, etc. I need a script to give me the OU that contains that PC. Such as Austin or Riverside, not Domain Computers. I have tried a couple of different scripts, and they work when run from the pc itself. But I need to run this on the server and query for a bunch of different pc names. Any suggestions on which script would work for that?
|
|
Top
|
|
|
|
#186643 - 2008-04-02 05:11 PM
Re: Find OU of PC
[Re: Mike1982]
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4562
Loc: USA
|
The first part of the following article would apply here: Hey Scripting Guy: How Can I Move a Computer From an Unknown OU into a Known OU? http://www.microsoft.com/technet/scriptcenter/resources/qanda/jun06/hey0623.mspx
This is vbs, but converting it to kix should not be to difficult, or at the least give it a shot, and we can help from there.
|
|
Top
|
|
|
|
#186644 - 2008-04-02 05:59 PM
Re: Find OU of PC
[Re: Allen]
|
Witto
MM club member
   
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
Allen, I am trying to convert this. I have the impression that the lines:
- objCommand.Properties("Page Size") = 1000
- objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
give a problem during conversion...
|
|
Top
|
|
|
|
#186652 - 2008-04-02 10:31 PM
Re: Find OU of PC
[Re: Les]
|
Les
KiX Master
   
Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
|
OOps, my bad... it was InContainer() that I modified.
;FUNCTION InContainer()
;http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=12;t=000179
;AUTHOR Howard A. Bullock (hbullock@tycoelectronics.com)
;
;VERSION 1.3 (modified by Les Ligetfalvy)
;
Function InContainer ($Container, $NameType, $Name)
Dim $CurrentContainer, $Name1, $Name2
select
case $NameType = 'Computer' $Name1 = @Domain + '\' + $Name + '$'
case $NameType = 'User' $Name1 = @LDomain + '\' + @UserID
case 1 $Name1 = ''
endselect
if $Name1 <> ''
$Name2 = TranslateName (3, '', 3, $Name1, 1)
if $Name2[1] = 0
$CurrentContainer = substr($Name2[0], instr($Name2[0], ',')+1)
select
case $CurrentContainer=$Container $InContainer = 1, $Name2[1], $Name2[2], $Name2[0]
case instr($Name2[0], $Container) $InContainer = 2, $Name2[1], $Name2[2], $Name2[0]
case 1 $InContainer = 0, $Name2[1], $Name2[2]
endselect
else
$InContainer = -2, $Name2[1], $Name2[2]
endif
else
$InContainer = -1, 0, '',''
endif
EndFunction
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.
|
|
Top
|
|
|
|
#186655 - 2008-04-02 11:25 PM
Re: Find OU of PC
[Re: Allen]
|
Witto
MM club member
   
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
|
|
Top
|
|
|
|
#186666 - 2008-04-03 09:20 AM
Re: Find OU of PC
[Re: Witto]
|
Witto
MM club member
   
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
I just feel an UDF coming This can also translate group names to DN Just give a group name and don't add a $ at the end
; =========================================================================================== ; ; Script Information ; ; Title: GetComputerDN ; Author: Wim Rotty ; Description: Get Distinguished Name of computer via NetBios name ; ; ; =========================================================================================== ;Script Options If Not @LOGONMODE Break On Else Break Off EndIf Dim $RC $RC = SetOption("Explicit", "On") $RC = SetOption("NoMacrosInStrings", "On") $RC = SetOption("NoVarsInStrings", "On") If @SCRIPTEXE = "KIX32.EXE" $RC = SetOption("WrapAtEOL", "On") EndIf
;Declare variables Dim $objSystemInfo Dim $strDomain Dim $objNetwork Dim $strComputer Dim $strComputerDN
;Initialize variables
;Code ;Get the NETBIOS name of the domain $objSystemInfo = CreateObject("ADSystemInfo") $strDomain = $objSystemInfo.DomainShortName
; Get the name of the computer $objNetwork = CreateObject("Wscript.Network") $strComputer = $objNetwork.ComputerName
; Call function to return the distinguished name (DN) of the computer $strComputerDN = getComputerDN($strComputer,$strDomain)
? $strComputerDN
;Personal UDF Section
;UDF Section
Function getComputerDN($strComputer,$strDomain) ; Constants required for name translate Dim $ADS_NAME_INITTYPE_GC Dim $ADS_NAME_TYPE_NT4 Dim $ADS_NAME_TYPE_1779 $ADS_NAME_INITTYPE_GC = 3 $ADS_NAME_TYPE_NT4 = 3 $ADS_NAME_TYPE_1779 = 1 ; Function to get the distinguished name of a computer ; from the NETBIOS name of the computer (strcomputer) ; and the NETBIOS name of the domain (strDomain) using ; name translate
Dim $objTrans $objTrans = CreateObject("NameTranslate") ; Initialize name translate using global catalog $objTrans.Init($ADS_NAME_INITTYPE_GC, "") ; Input computer name (NT Format) $objTrans.Set($ADS_NAME_TYPE_NT4, $strDomain + "\" + $strComputer + "$") ; Get Distinguished Name. $getComputerDN = $objTrans.Get($ADS_NAME_TYPE_1779)
EndFunction |
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 1198 anonymous users online.
|
|
|