Photo Gallery
Member List
Search
Calendars
FAQ
Ticket List
Log Out
Forums
Register
Login
My Profile
Inbox
Address Book
My Subscription
My Forums
Get DN of Computer
Logged in as: Guest
arrSession:exec spGetSession 2,16,27103
Active Users: There are
0
members and
0
guests.
Users viewing this topic: none
Printable Version
All Forums
>>
[Scripting]
>>
Post a VBScript
>> Get DN of Computer
Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page:
[1]
Login
Message
<< Older Topic
Newer Topic >>
Get DN of Computer -
10/19/2005 11:23:24 PM
mbouchard
Posts: 1861
Score: 14
Joined: 5/15/2003
From: USA
Status:
offline
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
Post #: 1
If you found our site useful please link to us
<a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>
.
All Forums
>>
[Scripting]
>>
Post a VBScript
>> Get DN of Computer
Page:
[1]
Jump to:
Select a Forum
All Forums
----------------------
[Welcome]
- - Forum Rules
- - Test Posting Messages
- - New Member Area/Introduction
[Scripting]
- - WSH & Client Side VBScript
- - WSH & Client Side VBScript Tutorial
- - Post a VBScript
- - Windows PowerShell
- - ASP
- - ASP.NET
- - Windows Script Components
[General Forum]
- - Other Programming/Scripting Languages
- - Suggestions & Feedback
- - Off-Topic Lounge
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
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
Forum Software ©
ASPPlayground.NET
Advanced Edition
2.5.5 ANSI