Welcome !
         

 Get DN of Computer

Author Message
mbouchard

  • Total Posts : 2160
  • Scores: 35
  • Reward points : 0
  • Joined: 5/15/2003
  • Location: USA
  • Status: offline
Get DN of Computer Thursday, October 20, 2005 12:23 AM (permalink)
0
While I didn't originally write this script, I thought others might be interested in it.
  'To determine the OU could be more complex. If the client
  'is W2k or XP, use ADSystemInfo to get both user and
  'computer DistinguishedName, which includes the OU
  'information.
  
  Dim sDNSDomain, oTrans, sNetBiosDomain, sAdsPath, sComputer, oUser
  Dim WshNetwork : Set WshNetwork = WScript.CreateObject("WScript.Network")
  
  ' Determine DNS domain name from RootDSE object.
  Dim oRoot : Set oRoot = GetObject("LDAP://RootDSE")
  sDNSDomain = oRoot.Get("DefaultNamingContext")
  ' Use the NameTranslate object to find the NetBIOS
  ' domain name from the DNS domain name.
  Set oTrans = CreateObject("NameTranslate")
  oTrans.Init 3, sDNSDomain
  oTrans.Set 1, sDNSDomain
  sNetBIOSDomain = oTrans.Get(3)
  
  ' Use NameTranslate to convert the NT user name to the
  ' DistinguishedName required for the LDAP provider.
  oTrans.Init 1, Left(sNetBIOSDomain, _
    Len(sNetBIOSDomain) - 1)
  oTrans.Set 3, sNetBIOSDomain & sNTName
  sAdsPath = oTrans.Get(1)
  
  ' Bind to the user object in AD with the LDAP provider.
  Set oUser = GetObject("LDAP://" & sAdsPath)
  
  ' Use NameTranslate to convert the NT name of the computer
  ' to the DistinguishedName required by LDAP.
  ' Computer names must end with "$".
  sComputer = InputBox("Please enter ComputerName, hit enter if Local PC.","Enter PC Name", "Local")'
  If ucase(sComputer) = "LOCAL" then
      sComputer = WshNetwork.ComputerName
  ElseIf IsEmpty(sComputer) Then
      Msgbox "Cancel Clicked, Quitting Script"
      wscript.Quit
  End If
  
  oTrans.Set 3, sNetBIOSDomain & sComputer & "$"
  sAdsPath = oTrans.Get(1)
  
  ' Bind to the computer object in AD with the LDAP provider.
  Set oComputer = GetObject("LDAP://" & sAdsPath) 
  'Should be able to add objComputer.DeleteObject (0) here to delete the PC.
  
  msgbox sAdsPath

 
#1
    xterso

    • Total Posts : 1
    • Scores: 0
    • Reward points : 0
    • Joined: 4/13/2009
    • Status: offline
    RE: Get DN of Computer Monday, April 13, 2009 6:51 PM (permalink)
    0
    Very useful code, thanks. But what is the use of "sNtName" in there? I couldn't understand.
     
    #2
      Online Bookmarks Sharing: Share/Bookmark

      Jump to:

      Current active users

      There are 0 members and 1 guests.

      Icon Legend and Permission

      • New Messages
      • No New Messages
      • Hot Topic w/ New Messages
      • Hot Topic w/o New Messages
      • Locked w/ New Messages
      • Locked w/o New Messages
      • Read Message
      • Post New Thread
      • Reply to message
      • Post New Poll
      • Submit Vote
      • Post reward post
      • Delete my own posts
      • Delete my own threads
      • Rate post

      2000-2014 ASPPlayground.NET Forum Version 3.9