Showing posts with label active directory. Show all posts
Showing posts with label active directory. Show all posts

Tuesday, January 6, 2009

What happens if two AD objects have the same RDN?

Every Active Directory (AD) object has a distinguished name (DN—e.g., CN=John Savill,CN=Users,DC=SavillTech,DC=Com) that uniquely identifies the object and its position in AD. The system also creates a relative distinguished name (RDN), which is a name relative to the container (e.g., CN=John Savill for the user).
Two objects with the same RDN can't exist in one container. For example, in the container CN=Users,DC=SavillTech, CN=John Savill and OU=John Savill are allowed because one is a user and the other is an organisational unit (OU). However, CN=John Savill and CN=John Savill aren't allowed.

The only way you can have a duplicate RDN is if two objects are created on different domain controllers (DCs). But at the next replication cycle, the system will rename the older object.


To find objects that the system has renamed because of RDN collisions, use the search.vbs script in \support\tools\support.cab as follows:

cscript search.vbs "LDAP:///dc=,dc=com" 
/C:"(CN=*\0ACNF:*)" /P:distinguishedName /S:SubTree 
Any matches will display the RDN for the renamed objects.

Monday, December 8, 2008

ad blogs


Here it is (in no particular order): By Tony Murray  
Ask The Directory Services Team. Kind of self-explanatory - content from the Microsoft DS Team.
Group Policy Team Blog. Similar to the above, but from Microsoft’s Group Policy team.
BPuhl’s Blog. Brian Puhl works as an Active Directory engineer for Microsoft’s IT department.
Dirteam.com / ActiveDir.org Blogs. Includes individual blogs from some of the foremost AD experts.
joeware - never stop exploring... Joe Richard’s blog.  Need I say more?
markwilson.it  Mark Wilson's blog.  Not purely AD related, but some good content
Michael's meanderings... Michael B Smith's blog.  Mostly Exchange-related content, but with a healthy dose of AD thrown in.
Open a Socket! Tony Murray's blog.  A fair chunk of it is AD related.
Directory Services/Active Directory.  Ulf B. Simon-Weidner's Blog
BSonPoSH.  Mostly Powershell content, but with some AD too.  From the aptly named Brendon Shell.
Aktives Verzeichnis Blog.  German-language AD blog from Microsoft.
Brian Desmond.  Blog by DS MVP Brian Desmond.
The Swede's blog.  Jimmy "The Swede" Andersson's blog.

Sunday, November 30, 2008

Export Active Directory Lists - updated

Corrected routine to work with any domain. This script uses various small BAT, VBS and EXE utilities. The beauty of this script is the way it reads the top-level members of a group, then process this list, determining which members are users and which ones are nested groups. It writes out the users and expands the nested groups. It then writes out the users and expands and further nested sub-group. Finally, it writes all this out to a TXT file, listing the groups and sub-groups at the top, and users below. The list is sorted and duplicate names are removed to take into account a use belonging to more than one nested list.

Use the active directory MMC (View-Advanced Features)to obtain the Canonical name of object. See the readme file.

Zipfile 12138ADGroupMembers.zip

Readme 10530Readme.doc

Monday, February 25, 2008

ad groups\sql

PowerShell for Active Directory Examples « Dmitry’s PowerBlog PowerShell and beyond
AD cmdlets and domain statistics « Dmitry’s PowerBlog PowerShell and beyond
PowerGUI - Administrative Powershell Console Finding out the largest group in AD ...
PowerGUI - Administrative Powershell Console Mail Enabled Contacts in W2K3 ...
Hey, Scripting Guy! How Can I Use Windows PowerShell to Retrieve the Non-Unique Items in a List
--o-- PowerShelled PowerShell and Active Directory Part 9 (nested groups)
Windows Powershell Working with Active Directory -- TechNet Magazine, June 2007
Managing group membership in Active Directory with PowerShell (Part 1) Lead, Follow, or Move
Managing group membership in Active Directory with PowerShell (Part 2) Lead, Follow, or Move
PowerGUI - Administrative Powershell Console A quick intro to the Management Shell ...
Import-Export Members to a Group
List All Members of a Grouo, Including Members of Nested Groups
Project84 - Using PowerShell to find nested Groups for Active Directory Migration
AD cmdlets 1.0.3 to 1.0.4 upgrade « Dmitry’s PowerBlog PowerShell and beyond
Redmond Column Membership Has Its Privileges

windows forms
--o-- PowerShelled PowerShell Calendar Function (GUI)
Nivot Ink - Using Windows Forms Controls in PowerShell #1 ListBox
Hey, Scripting Guy! How Can I Remove EverythingFrom an Active Directory Group Except Other Groups
Hey, Scripting Guy! How Can I Configure an Active Directory Account So the Password Never Expires



Remove Password Never Expires on everyone in my AD domain - dBforums
sql
Hey, Scripting Guy! How Can I Enumerate All the Objects in an Active Directory OU
Hey, Scripting Guy! How Can I Determine if an OU is Blocking Group Policy Inheritance
Hey, Scripting Guy! How Can I List All the Sub-OUs in an OU
Allen White Accessing SQL Server data through PowerShell
AzamSharp Using PowerShell to View Images in Database
Allen White Using PowerShell and SQL Server Together
Allen White PowerShell, SQL Server and Large Resultsets
Learn SQL Server
T-SQL Programming
Custom reports in Management Studio, using the Performance Dashboard
Jeffrey McManus Database Queries with Windows Powershell
Hey, Scripting Guy! How Can I Use Windows PowerShell to Pull Records From a Microsoft Access Database
Comparing Python and PowerShell DBA Scripting
Beginning SQL Server 2005 Reporting Services Part 1
Precision Computing - Interacting with SQL Databases in PowerShell Invoke-SqlCommand
Reporting Services Cribsheet

ad groups\sql

PowerShell for Active Directory Examples « Dmitry’s PowerBlog PowerShell and beyond
AD cmdlets and domain statistics « Dmitry’s PowerBlog PowerShell and beyond
PowerGUI - Administrative Powershell Console Finding out the largest group in AD ...
PowerGUI - Administrative Powershell Console Mail Enabled Contacts in W2K3 ...
Hey, Scripting Guy! How Can I Use Windows PowerShell to Retrieve the Non-Unique Items in a List
--o-- PowerShelled PowerShell and Active Directory Part 9 (nested groups)
Windows Powershell Working with Active Directory -- TechNet Magazine, June 2007
Managing group membership in Active Directory with PowerShell (Part 1) Lead, Follow, or Move
Managing group membership in Active Directory with PowerShell (Part 2) Lead, Follow, or Move
PowerGUI - Administrative Powershell Console A quick intro to the Management Shell ...
Import-Export Members to a Group
List All Members of a Grouo, Including Members of Nested Groups
Project84 - Using PowerShell to find nested Groups for Active Directory Migration
AD cmdlets 1.0.3 to 1.0.4 upgrade « Dmitry’s PowerBlog PowerShell and beyond
Redmond Column Membership Has Its Privileges

windows forms
--o-- PowerShelled PowerShell Calendar Function (GUI)
Nivot Ink - Using Windows Forms Controls in PowerShell #1 ListBox
Hey, Scripting Guy! How Can I Remove EverythingFrom an Active Directory Group Except Other Groups
Hey, Scripting Guy! How Can I Configure an Active Directory Account So the Password Never Expires



Remove Password Never Expires on everyone in my AD domain - dBforums
sql
Hey, Scripting Guy! How Can I Enumerate All the Objects in an Active Directory OU
Hey, Scripting Guy! How Can I Determine if an OU is Blocking Group Policy Inheritance
Hey, Scripting Guy! How Can I List All the Sub-OUs in an OU
Allen White Accessing SQL Server data through PowerShell
AzamSharp Using PowerShell to View Images in Database
Allen White Using PowerShell and SQL Server Together
Allen White PowerShell, SQL Server and Large Resultsets
Learn SQL Server
T-SQL Programming
Custom reports in Management Studio, using the Performance Dashboard
Jeffrey McManus Database Queries with Windows Powershell
Hey, Scripting Guy! How Can I Use Windows PowerShell to Pull Records From a Microsoft Access Database
Comparing Python and PowerShell DBA Scripting
Beginning SQL Server 2005 Reporting Services Part 1
Precision Computing - Interacting with SQL Databases in PowerShell Invoke-SqlCommand
Reporting Services Cribsheet

Friday, February 15, 2008

Microsoft Active Directory Topology Diagrammer

Microsoft Active Directory Topology Diagrammer
Brief Description
The Microsoft Active Directory Topology Diagrammer reads an Active Directory configuration using ActiveX Data Objects (ADO), and then automatically generates a Visio diagram of your Active Directory and /or your Exchange 200x Server topology. The diagramms include domains, sites, servers, administrative groups, routing groups and connectors and can be changed manually in Visio if needed.

Sunday, December 2, 2007

Perform an AD Search Using Alternate Credentials

Perform a Search Using Alternate Credentials


Microsoft Windows XP - Create a shortcut using runas command parameters

'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 2007
'
' NAME:
'
' AUTHOR: mike mccafferty , mmcc
' DATE : 12/2/2007
'
' COMMENT: sites of interest
' http://www.windowsitlibrary.com/Content/2026/08/2.html
' using runAs with a shortcut
' http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/windows_security_runas_shortcut.mspx?mfr=true
' ADU&C runas /user:DomainName\administrator "mmc %windir%\system32\dsa.msc"
' ADU&C runas /netonly /user:DomainName\UserName "mmc.exe dsa.msc"
'




'==========================================================================
Sub WMIalternateCreds1()

' From the book "Windows XP Cookbook"
' ISBN: 0596007256

' Note that you cannot use this to connect to the local machine.
' ------ SCRIPT CONFIGURATION ------
strServer = "" ' e.g. wks01
strUser = "" ' e.g. AMER\rallen.adm
strPasswd = ""
' ------ END CONFIGURATION ---------
on error resume next
set objLocator = CreateObject("WbemScripting.SWbemLocator")
set objWMI = objLocator.ConnectServer(strServer, "root\cimv2", _
strUser, strPasswd)
if Err.Number <> 0 then
WScript.Echo "Authentication failed: " & Err.Description
end if

' Now you can use the objWMI object to get an instance of a class
' or perform a WQL query. Here is an example:
colDisks = objWMI.InstancesOf("Win32_LogicalDisk")


End Sub


Sub ADalternateCreds2()
Dim objConn
Set objConn = CreateObject("ADODB.Connection")
objConn.ConnectionString = "Provider=ADSDSOObject;" & _
"User ID=MyUserID;Password=MyPassword;"
objConn.Open

End Sub

Sub ADalternateCreds3()

' You get a choice, you can either
' hard-code the Domain Name (or a Domain Controller Name) only,
' then get the Distinguished Name from Root DSE:
'



Const DOMAIN_NAME = ""

Set objLDAP = GetObject("LDAP:")
Set objRootDSE = objLDAP.OpenDSObject("LDAP://" & DOMAIN_NAME &_
"/RootDSE", strUsername, strPassword)


'Or Hardcode both, and just connect directly to the target container:


Const DOMAIN_NAME = ""
Const CONTAINER_PATH = "OU=SomeOU,DC=SomeDomain,DC=local"

Set objLDAP = GetObject("LDAP:")
Set objRootDSE = objLDAP.OpenDSObject("LDAP://" & DOMAIN_NAME &_
"/" & CONTAINER_PATH, strUsername, strPassword)


' You would have to specify a value for strUsername and strPassword in all cases.
'
' Personally, I favour pulling the Distinguished Name from RootDSE rather than hard-coding it. It just makes things easier to maintain for me.
'
' Chris

End Sub


Sub ADalternateCreds1()
On Error Resume Next

Const ADS_SCOPE_SUBTREE = 2

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Properties("User ID") = "Administrator"
objConnection.Properties("Password") = "+77m5trgJo!"
objConnection.Properties("Encrypt Password") = TRUE
objConnection.Properties("ADSI Flag") = 1
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

objCommand.CommandText = _
"SELECT Name FROM 'LDAP://dc=fabrikam,dc=com' WHERE objectCategory='user'"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst

Do Until objRecordSet.EOF
Wscript.Echo objRecordSet.Fields("Name").Value
objRecordSet.MoveNext
Loop

end sub

Thursday, November 22, 2007

Hilltop Lab fancy scripts ADSI Scripting for Administering Windows 2000/2003 Networks

http://www.rlmueller.net/products.htm

name translate function

http://www.rlmueller.net/NameTranslateFAQ.htm


Frequently Asked Questions about NameTranslate
What is NameTranslate?
On What clients is NameTranslate available?
What can NameTranslate do for me?
Why do I need to use NameTranslate?
How do I use NameTranslate?
How about a quick example of the use of NameTranslate?
What are the options when I initialize NameTranslate?
What formats are accepted by the Set and Get methods of NameTranslate?
How do I convert an NT name to a Distinguished Name?
How do I convert the NetBIOS name of a computer to it's Distinguished Name?
How do I convert a Distinguished Name to an NT name?
How do I convert an NT Name to a Display Name?
How do I convert an NT Name to a User Principal Name?
How do I convert an NT Name to a GUID?
Can I convert the Display Name of a user to the Distinguished Name?
How do I find the NetBIOS name of the domain?
How do I specify credentials with NameTranslate?
Can I convert the names of more than one object at a time?
What errors can occur?
Where can I get more information?
1. What is NameTranslate?
NameTranslate refers to the IADsNameTranslate interface, which can be used to convert the names of Active Directory objects from one format to another.
2. On what clients is NameTranslate available?
The IADsNameTranslate interface is available on any client with Windows 2000 or above, or any other 32-bit client with DSClient installed. On Windows 95, Windows 98, Windows ME, or Windows NT clients, if DSClient is not installed, the IADsNameTranslate interface is only available if ADS is installed. The object is provided by ADSI on the client, but it must connect to Active Directory. The user must either be authenticated to the domain, or must provide credentials.
3. What can NameTranslate do for me?
The IADsNameTranslate interface can translate Active Directory object names between several formats. NameTranslate can be used to convert the name of any Active Directory object from one format to another. Among the formats supported by NameTranslate are:
Distinguished Names - format as specified in RFC 1779. For example cn=TestUser,ou=Sales,dc=MyDomain,dc=com.
NT format - the name format used in Windows NT 4.0. For example MyDomain\TestUser, where MyDomain is the NetBIOS name of the domain and TestUser is the NT name of the object. The sAMAccountName attribute is the NT name (or NetBIOS Name) of the object.
Canonical Name - For example MyDomain.com/Jim Anderson, where MyDomain.com is the DNS name of the domain and "Jim Anderson" is the Relative Distinguished Name (RDN, or the "cn" attribute, or common name, for most classes of objects) of the object.
Display Name - The displayName attribute of the object, for example "Jim L. Anderson".
User Principal Name (UPN) of the object. For example JimAnderson@MyDomain.com.
GUID - The Global Unique Identifier. For example {95ee9fff-3436-11d1-b2b0-d15ae3ac8436}.
4. Why do I need to use NameTranslate?
If you use the LDAP provider, which is more powerful and exposes more attributes than the WinNT provider, you must bind to Active Directory objects with the Distinguished Name of the object. However, most people refer to objects by their NT names. Users call this their UserName, or User ID. This single string value uniquely identifies the account in Active Directory. It is easier to remember and deal with than the lengthy Distinguished Name with its many components. In addition, the WshNetwork object can determine the NT name of the current user and the computer, but not the Distinguished Name.
5. How do I use NameTranslate?
The steps required to convert names with the IADsNameTranslate interface are:
Bind to the NameTranslate object.
Initialize the NameTranslate object by calling the Init method and specifying the type of translation.
Use the Set method of the NameTranslate object to specify the Active Directory object whose name will be converted.
Use the Get method of the NameTranslate object to retrieve the name of the Active Directory object in the desired format.
6. How about a quick example of the use of NameTranslate?
The VBScript code below converts the NT name of a user to the Distinguished Name:
' Constants for the NameTranslate object.
Const ADS_NAME_INITTYPE_GC = 3Const ADS_NAME_TYPE_NT4 = 3Const ADS_NAME_TYPE_1779 = 1' Specify the NetBIOS name of the domain and the NT name of the user.strNTName = "MyDomain\TestUser"' Use the NameTranslate object to convert the NT user name to the' Distinguished Name required for the LDAP provider.Set objTrans = CreateObject("NameTranslate")
' Initialize NameTranslate by locating the Global Catalog.objTrans.Init ADS_NAME_INITTYPE_GC, ""' Use the Set method to specify the NT format of the object name.objTrans.Set ADS_NAME_TYPE_NT4, strNTName
' Use the Get method to retrieve the RPC 1779 Distinguished Name.strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)

' Escape any "/" characters with backslash escape character.
' All other characters that need to be escaped will be escaped.
strUserDN = Replace(strUserDN, "/", "\/")' Bind to the user object in Active Directory with the LDAP provider.Set objUser = GetObject("LDAP://" & strUserDN)

The following characters can appear in Distinguished Names, but must be escaped with the backslash "\" escape character:

,\/#+<>;"=

The Get method of the NameTranslate object will return the Distinguished Name with these characters properly escaped, with the exception of the forward slash character "/". If this character is found in the Distinguished Name, it should be replaced by "\/" before using the Distinguished Name in a binding string. Otherwise, an error will be raised.
7. What are the options when I initialize NameTranslate?
The Init method of the NameTranslate object accepts any of the following values:
Const ADS_NAME_INITTYPE_DOMAIN = 1
Const ADS_NAME_INITTYPE_SERVER = 2
Const ADS_NAME_INITTYPE_GC = 3
With ADS_NAME_INITTYPE_DOMAIN you specify the domain that the NameTranslate object will connect to. With ADS_NAME_INITTYPE_SERVER you specify the server (domain controller) that the NameTranslate object will connect to. With ADS_NAME_INITTYPE_GC the NameTranslate object locates a Global Catalog. Unless you are converting the name of an object in another domain, there is no need to use anything other than ADS_NAME_INITTYPE_GC. Code examples using each follow:
Const ADS_NAME_INITTYPE_DOMAIN = 1
Set objTrans = CreateObject("NameTranslate")
objTrans.Init ADS_NAME_INITTYPE_DOMAIN, "MyDomain.com"

Const ADS_NAME_INITTYPE_SERVER = 2
Set objTrans = CreateObject("NameTranslate")
objTrans.Init ADS_NAME_INITTYPE_SERVER, "MyServer"

The server name can be in the form "MyServer" or "MyServer.MyDomain.com"

Const ADS_NAME_INITTYPE_GC = 3
Set objTrans = CreateObject("NameTranslate")
objTrans.Init ADS_NAME_INIITTYPE_GC, ""
8. What formats are accepted by the Set and Get methods of NameTranslate?
The following constants define the formats used with the Set and Get methods to convert names:
Const ADS_NAME_TYPE_1779 = 1
Const ADS_NAME_TYPE_CANONICAL = 2
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_DISPLAY = 4
Const ADS_NAME_TYPE_DOMAIN_SIMPLE = 5
Const ADS_NAME_TYPE_ENTERPRISE_SIMPLE = 6
Const ADS_NAME_TYPE_GUID = 7
Const ADS_NAME_TYPE_UNKNOWN = 8
Const ADS_NAME_TYPE_USER_PRINCIPAL_NAME = 9
Const ADS_NAME_TYPE_CANONICAL_EX = 10
Const ADS_NAME_TYPE_SERVICE_PRINCIPAL_NAME = 11
Const ADS_NAME_TYPE_SID_OR_SID_HISTORY_NAME = 12
9. How do I convert an NT name to a Distinguished Name?
The VBScript example below converts the NT name of any user, in conjunction with the NetBIOS name of the domain, to the Distinguished Name of the user object:
' Constants for the NameTranslate object.
Const ADS_NAME_INITTYPE_GC = 3Const ADS_NAME_TYPE_NT4 = 3Const ADS_NAME_TYPE_1779 = 1' Specify the NetBIOS name of the domain.
strNetBIOSDomain = "MyDomain"

' Specify the NT name of the user.strNTName = "TestUser"' Use the NameTranslate object to convert the NT user name to the' Distinguished Name required for the LDAP provider.Set objTrans = CreateObject("NameTranslate")
' Initialize NameTranslate by locating the Global Catalog.objTrans.Init ADS_NAME_INITTYPE_GC, ""' Use the Set method to specify the NT format of the object name.objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strNTName
' Use the Get method to retrieve the RPC 1779 Distinguished Name.strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
' Escape any "/" characters with backslash escape character.
' All other characters that need to be escaped will be escaped.
strUserDN = Replace(strUserDN, "/", "\/")' Bind to the user object in Active Directory with the LDAP provider.Set objUser = GetObject("LDAP://" & strUserDN)
If the object with the specified NT name does not exist, the Set method of the NameTranslate object raises an error. To programmatically determine the NetBIOS name of the domain you have authenticated to, see FAQ # 16 below.
10. How do I convert the NetBIOS name of a computer to it's Distinguished Name?
Computer accounts are just like user accounts, except that the sAMAccountName attribute of computer objects is terminated with "$". The NT name of a computer is the NetBIOS name with "$" appended on the end. The WshNetwork object returns the NetBIOS name of the computer. Before you can convert this name with NameTranslate, you must append the "$". For example:
' Constants for the NameTranslate object.
Const ADS_NAME_INITTYPE_GC = 3Const ADS_NAME_TYPE_NT4 = 3Const ADS_NAME_TYPE_1779 = 1' Specify the NetBIOS name of the domain.
strNetBIOSDomain = "MyDomain"

' Retrieve the NetBIOS name of the computer object from WshNetwork.
' Append a "$" on the end.
Set objNetwork = GetObject("Wscript.Network")
strComputer = objNetwork.ComputerName & "$"' Use the NameTranslate object to convert the NT computer name to the' Distinguished Name required for the LDAP provider.Set objTrans = CreateObject("NameTranslate")
' Initialize NameTranslate by locating the Global Catalog.objTrans.Init ADS_NAME_INITTYPE_GC, ""' Use the Set method to specify the NT format of the object name.objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strComputer
' Use the Get method to retrieve the RPC 1779 Distinguished Name.strComputerDN = objTrans.Get(ADS_NAME_TYPE_1779)' Bind to the computer object in Active Directory with the LDAP provider.Set objComputer = GetObject("LDAP://" & strComputerDN)
This assumes that the Distinguished Name of the computer object does not contain any forward slash characters "/". If there are any forward slash characters, they must be escaped with the backslash escape character "\" to avoid an error when you bind to the object.
If you use NameTranslate to convert the Distinguished Name of a computer object to the NT from, you will need to parse the value returned by the Get method for the NetBIOS domain name and the NT name of the computer. If you want the NetBIOS name of the computer, you will need to strip off the trailing "$".
11. How do I convert a Distinguished Name to an NT name?
The VBScript example below converts the Distinguished Name of any user object to the NT form, which includes the NetBIOS name of the domain and the NT name of the user.
' Constants for the NameTranslate object.
Const ADS_NAME_INITTYPE_GC = 3Const ADS_NAME_TYPE_NT4 = 3Const ADS_NAME_TYPE_1779 = 1' Specify the Distinguished Name of the user.
strUserDN = "cn=TestUser,ou=Sales,dc=MyDomain,dc=com"

' Use the NameTranslate object to convert the Distinguished Name
' of the user to the NT Name required for the WinNT provider.Set objTrans = CreateObject("NameTranslate")
' Initialize NameTranslate by locating the Global Catalog.objTrans.Init ADS_NAME_INITTYPE_GC, ""' Use the Set method to specify the RPC 1779 format of the object name.objTrans.Set ADS_NAME_TYPE_1779, strUserDN
' Use the Get method to retrieve the NT Name.strNTName = objTrans.Get(ADS_NAME_TYPE_NT4)

' Parse for the NetBIOS name of the domain and the NT name of the user.
strNetBIOSDomain = Mid(strNTName, 1, InStr(strNTName, "\") - 1)
strUserName = Mid(strNTName, InStr(strNTName, "\") + 1)' Bind to the user object in Active Directory with the WinNT provider.Set objUser = GetObject("WinNT://" & strNetBIOSDomain & "/" & strUserName)
If the object with the specified Distinguished Name does not exist, the Set method of the NameTranslate object will raise an error.
12. How do I convert an NT Name to a Display Name?
The VBScript example below converts the NT form of any user name to the Display Name of the user object (the value of the displayName attribute):
' Constants for the NameTranslate object.
Const ADS_NAME_INITTYPE_GC = 3Const ADS_NAME_TYPE_NT4 = 3Const ADS_NAME_TYPE_DISPLAY = 4' Specify the NetBIOS name of the domain.
strNetBIOSDomain = "MyDomain"

' Specify the NT name of the user.strNTName = "TestUser"' Use the NameTranslate object to convert the NT user name to the' Distinguished Name required for the LDAP provider.Set objTrans = CreateObject("NameTranslate")
' Initialize NameTranslate by locating the Global Catalog.objTrans.Init ADS_NAME_INITTYPE_GC, ""' Use the Set method to specify the NT format of the object name.objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strNTName
' Use the Get method to retrieve the Display Name.strDisplayName = objTrans.Get(ADS_NAME_TYPE_DISPLAY)
If the NT name of the user does not exist, the Set method of the NameTranslate object raises an error. However, if the object does not have a value assigned to the displayName attribute, the Get method of the NameTranslate object raises an error.13. How do I convert an NT Name to a User Principal Name?
The VBScript example below converts the NT form of any user name to the User Principal Name (the value of the userPrincipalName attribute):
' Constants for the NameTranslate object.
Const ADS_NAME_INITTYPE_GC = 3Const ADS_NAME_TYPE_NT4 = 3Const ADS_NAME_TYPE_USER_PRINCIPAL_NAME = 9' Specify the NetBIOS name of the domain.
strNetBIOSDomain = "MyDomain"

' Specify the NT name of the user.strNTName = "TestUser"' Use the NameTranslate object to convert the NT user name to the' Distinguished Name required for the LDAP provider.Set objTrans = CreateObject("NameTranslate")
' Initialize NameTranslate by locating the Global Catalog.objTrans.Init ADS_NAME_INITTYPE_GC, ""' Use the Set method to specify the NT format of the object name.objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strNTName
' Use the Get method to retrieve the User Principal Name.strUserUPN = objTrans.Get(ADS_NAME_TYPE_USER_PRINCIPAL_NAME)
If the NT name of the user does not exist, the Set method of the NameTranslate object raises an error. However, if the object does not have a value assigned to the userPrincipalName attribute, the Get method of the NameTranslate object raises an error.14. How do I convert an NT Name to a GUID?
The VBScript example below converts the NT form of any user name to the GUID of the object. This is the value of the objectGUID attribute converted to a string format. It is also the value returned by the GUID property method of the object.
' Constants for the NameTranslate object.
Const ADS_NAME_INITTYPE_GC = 3Const ADS_NAME_TYPE_NT4 = 3Const ADS_NAME_TYPE_GUID = 7' Specify the NetBIOS name of the domain.
strNetBIOSDomain = "MyDomain"

' Specify the NT name of the user.strNTName = "TestUser"' Use the NameTranslate object to convert the NT user name to the' Distinguished Name required for the LDAP provider.Set objTrans = CreateObject("NameTranslate")
' Initialize NameTranslate by locating the Global Catalog.objTrans.Init ADS_NAME_INITTYPE_GC, ""' Use the Set method to specify the NT format of the object name.objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strNTName
' Use the Get method to retrieve the GUID of the user object.strUserGuid = objTrans.Get(ADS_NAME_TYPE_GUID)
If the NT name of the user does not exist, the Set method of the NameTranslate object raises an error.
15. Can I convert the Display Name of a user to the Distinguished Name?
Yes, you can, as long as the user has a Display Name that is unique. If you specify ADS_NAME_INITTYPE_GC, the Display Name must be unique in the forest. Otherwise, it must be unique in the domain. An error will be raised by the Set method if the Display Name value you specify does not uniquely identify the object. The corresponding attribute is displayName. Of course, the value cannot be empty (null). A VBScript example follows:
' Constants for the NameTranslate object.
Const ADS_NAME_INITTYPE_GC = 3Const ADS_NAME_TYPE_1779 = 1Const ADS_NAME_TYPE_DISPLAY = 4' Specify the Display Name of the user.
strDisplay = "Test User"

' Use the NameTranslate object to convert the Display Name' of the user to the Distinguished Name.Set objTrans = CreateObject("NameTranslate")
' Initialize NameTranslate by locating the Global Catalog.objTrans.Init ADS_NAME_INITTYPE_GC, ""' Use the Set method to specify the Display Name of the object name.objTrans.Set ADS_NAME_TYPE_DISPLAY, strDisplay
' Use the Get method to retrieve the Distinguished Name of the user object.strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
If the Distinguished Name has any forward slash characters "/", they should be escaped with the backslash escape character "\" before using the Distinguished Name to bind to the corresponding object.
16. How do I find the NetBIOS name of the domain?
Most uses of the NameTranslate object require the NetBIOS name of the domain. If the client OS is NT or above, the environment variable %USERDOMAIN% is the NetBIOS name of the domain the user authenticated to. In VBScript, you can use the WshShell object to retrieve the value of this environment variable. For example:
Set objShell = CreateObject("Wscript.Shell")
strNetBIOSDomain = objShell.Environment("Process").Item("userdomain")
On any client, you can use the RootDSE object to retrieve the default naming context, which is the Distinguished Name of the domain that the user authenticated to. Then, you can use the NameTranslate object to convert this to the NetBIOS name of the domain. For example:
' Constants for the NameTranslate object.Const ADS_NAME_INITTYPE_GC = 3Const ADS_NAME_TYPE_NT4 = 3Const ADS_NAME_TYPE_1779 = 1

' Determine DNS name of domain from RootDSE.Set objRootDSE = GetObject("LDAP://RootDSE")strDNSDomain = objRootDSE.Get("defaultNamingContext")' Use the NameTranslate object to find the NetBIOS domain name from the' DNS domain name.Set objTrans = CreateObject("NameTranslate")objTrans.Init ADS_NAME_INITTYPE_GC, ""objTrans.Set ADS_NAME_TYPE_1779, strDNSDomainstrNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4)' Remove trailing backslash.strNetBIOSDomain = Left(strNetBIOSDomain, Len(strNetBIOSDomain) - 1)
If the client is NT or above, you can also retrieve the NetBIOS domain name from the WshNetwork object. For example:
Set objNetwork = CreateObject("Wscript.Network")
strNetBIOSDomain = objNetwork.UserDomain
Finally, if the client is Windows 2000 or above, or NT with DSClient installed, you can use the WinNTSystemInfo object. For example:
Set objWinNTSysInfo = CreateObject("WinNTSystemInfo")
strNetBIOSDomain = objWinNTSysInfo.DomainName
You might attempt to retrieve the NetBIOS domain name from the domain object (binding with the DNS domain name retrieved from the RootDSE object). However, the nETBIOSName attribute of the domain object only has a value if the NetBIOS domain name is different from the Relative Distinguished Name of the domain (which is the top level domain component of the domain).
Note that the only method above that works on all clients (including Win9x) is the one that retrieves the DNS domain name from the RootDSE object and uses NameTranslate to convert this to the NT format.
17. How do I specify credentials with NameTranslate?
The InitEx method of the NameTranslate object is similar to the Init method, but allows you to specify a user name, domain, and password. The same connection options are supported. A VBScript example:
' Constants for the NameTranslate object.
Const ADS_NAME_INITTYPE_GC = 3Const ADS_NAME_TYPE_NT4 = 3Const ADS_NAME_TYPE_1779 = 1' Specify the NetBIOS name of the domain and the NT name of the user.strNTName = "MyDomain\TestUser"
' Specify a domain, user name, and password.
' The connection to Active Directory will be made with these credentials.
strDomain = "MyDomain"
strUser = "TestUser"
strPassword = "xyz321"
' Use the NameTranslate object to convert the NT user name to the' Distinguished Name required for the LDAP provider.Set objTrans = CreateObject("NameTranslate")
' Initialize NameTranslate by locating the Global Catalog.
' Specify credentials.objTrans.InitEx ADS_NAME_INITTYPE_GC, "", strUser, strDomain, strPassword' Use the Set method to specify the NT format of the object name.objTrans.Set ADS_NAME_TYPE_NT4, strNTName
' Use the Get method to retrieve the RPC 1779 Distinguished Name.strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
' Escape any "/" characters with backslash escape character.
' All other characters that need to be escaped will be escaped.
strUserDN = Replace(strUserDN, "/", "\/")' Bind to the user object in Active Directory with the LDAP provider.Set objUser = GetObject("LDAP://" & strUserDN)
18. Can I convert the names of more than one object at a time?
Yes, you can. The SetEx and GetEx methods of the NameTranslate object are similar to the Set and Get methods, except that they deal with arrays of names. A VBScript example:
' Constants for the NameTranslate object.
Const ADS_NAME_INITTYPE_GC = 3Const ADS_NAME_TYPE_NT4 = 3Const ADS_NAME_TYPE_1779 = 1' Specify the NT form of several user names.arrNTNames(0) = "MyDomain\TestUser"
arrNTNames(1) = "MyDomain\JoeSmith"
arrNTNames(2) = "MyDomain\MaryNelson"' Use the NameTranslate object to convert the NT user names to the' Distinguished Names required for the LDAP provider.Set objTrans = CreateObject("NameTranslate")
' Initialize NameTranslate by locating the Global Catalog.objTrans.Init ADS_NAME_INITTYPE_GC, ""' Use the SetEx method to specify the NT format of the object names.objTrans.Set ADS_NAME_TYPE_NT4, arrNTNames
' Use the GetEx method to retrieve the RPC 1779 Distinguished Names.arrUserDNs = objTrans.GetEx(ADS_NAME_TYPE_1779)
For k = 0 To UBound(arrUserDNs)
Wscript.Echo arrUserDNs(k)
Next
19. What errors can occur?
If the domain, server, or GC cannot be contacted, the Init method will raise an error. This will happen if you are not authenticated to the domain. You can use the InitEx method to specify user credentials. Of course, an error will be raised by the InitEx method if the credentials are incorrect, or if the domain, server, or GC cannot be contacted.
If the object with the name specified does not exist, the Set method will raise an error.
If the object does not have a value defined for the corresponding attribute, the Get method will raise an error. For example, if the displayName attribute has no value, the Get method will raise an error if you have specified ADS_NAME_TYPE_DISPLAY. Similarly, if userPrincipalName has no value, Get will raise an error if you have specified ADS_NAME_TYPE_USER_PRINCIPAL_NAME. Such an error will never occur if you attempt to retrieve a name in the formats ADS_NAME_TYPE_1779, ADS_NAME_TYPE_CANONICAL, ADS_NAME_TYPE_NT4, or ADS_NAME_TYPE_GUID because the corresponding attributes always have a value.
The Set method will raise an error if the value specified does not uniquely identify the object in Active Directory. For example, more than one user could have the same value assigned to the displayName attribute. If you specify the object with the Set method and ADS_TYPE_NAME_DISPLAY and specify a value that could identify more than one object, an error will be raised. Once again, note that this cannot happen with ADS_NAME_TYPE_1779, ADS_NAME_TYPE_CANONICAL, ADS_NAME_TYPE_NT4, ADS_NAME_TYPE_USER_PRINCIPAL_NAME, or ADS_NAME_TYPE_GUID, because the corresponding attribute values must be unique.
20. Where can I get more information?
For more information on NameTranslate, see the following links:
IADsNameTranslate Interface: http://msdn2.microsoft.com/en-us/library/Aa706046.aspx
ADS_NAME_INITTYPE_ENUM: http://msdn2.microsoft.com/en-us/library/Aa772266.aspx
ADS_NAME_TYPE_ENUM: http://msdn2.microsoft.com/en-us/library/Aa772267.aspx
Init Method: http://msdn2.microsoft.com/en-us/library/Aa706049.aspx
Set Method: http://msdn2.microsoft.com/en-us/library/Aa706053.aspx
Get Method: http://msdn2.microsoft.com/en-us/library/Aa706047.aspx
InitEx Method: http://msdn2.microsoft.com/en-us/library/Aa706050.aspx
SetEx Method: http://msdn2.microsoft.com/en-us/library/Aa706054.aspx
GetEx Method: http://msdn2.microsoft.com/en-us/library/Aa706048.aspx

Friday, October 19, 2007

Calculating the Last Logon Time

Calculating the Last Logon Time


Set objUser = GetObject("LDAP://cn=Ken Myer, ou=Finance, dc=fabrikam, dc=com")
Set objLastLogon = objUser.Get("lastLogonTimestamp")
intLastLogonTime = objLastLogon.HighPart * (2^32) + objLastLogon.LowPart
intLastLogonTime = intLastLogonTime / (60 * 10000000)
intLastLogonTime = intLastLogonTime / 1440
Wscript.Echo "Last logon time: " & intLastLogonTime + #1/1/1601#

Tuesday, August 14, 2007

Acctinfo.dll Windows Server 2003 Resource Kit Tools

Microsoft's Windows Server 2003 Resource Kit Tools are a set of tools to help administrators streamline management tasks such as troubleshooting operating system issues, managing Active Directory, configuring networking and security features, and automating application deployment. This segment of my in-depth review of these tools will explore the one listed first alphabetically: AccountInfo.dll, aka Acctinfo.dll.
Acctinfo.dll is actually a DLL. If you don't consider DLLs to be tools, you're probably wondering why it's in the kit at all. The reason is that it adds to the functionality of the Microsoft Management Console (MMC) Active Directory Users and Computers snap-in, a tool for managing your users, groups and computers.
Once you register the DLL, you'll get another tabbed option when looking at a user's account properties. On the tab, you'll find the following:
General Account Info, including: Lock Out status, Domain Password Policy being applied, Password Last Set date and Password Expiration date
Logon Information, including: Last Logon attempt, Logon Count, Last Logon and Logoff, Last Bad Logon Time, Bad Password Count
Active Directory account attributes, including: User Account Control, SID and SID History, GUID, User-DN-Site-Domain Controller (e.g., the account's Active Directory path). Warning: See the section below on issues regarding the "Set PW On Site DC" button.
System requirements for Acctinfo.dll
Windows Server 2003 or Windows 2000 Server operating system
You must be an Administrator to install Acctinfo.dll.
Acctinfo.dll must be registered on each computer on which Active Directory Users and Computers is employed to access user account information.
Installation of Acctinfo.dll
To install and register Acctinfo.dll, perform these three steps:
1. Copy the file Acctinfo.dll to the %windir%\system32 folder.
2. Start-->Run-->type: cmd
3. In the command window, type regsvr32 c:\windows\system32\acctinfo.dll. You should receive a dialog box that states the registration was successful.
To uninstall Acctinfo.dll, type regsvr32 /u c:\windows\system32\acctinfo.dll.
General use
The primary purpose of the Additional Account Info tab is to display account information. But it also allows you to change a user's password and unlock an account. Normally, an administrator would have to tab around to get to this information, which is likely the most commonly used functionality in your Active Directory network for managing user accounts. For many systems administrators, the tab basically becomes a one-stop shop for most of their daily user account administration needs.
Issues with Acctinfo.dll
The readme.htm file included with Acctinfo.dll lists five issues to be considered.
1. In some cases, the information is not actually stored in Active Directory, but is calculated only when needed. For example, the date that a user's password will expire is not stored in Active Directory. Active Directory stores the date that the password was last set and the maximum allowed password age (for example, passwords must be set every 60 days).
To determine the actual date that a password expires, you typically have to use scripts to retrieve this information and calculate the expiration date. Acctinfo.dll performs these calculations for you.
2. In some cases, information is stored locally rather than in Active Directory. For example, last logon and last logoff times are stored on each individual domain controller and are not replicated throughout the domain. Acctinfo.dll enables you to determine the last time a user logged on or logged off from a specified domain controller. If users are typically authenticated by the same domain controller, this will tell you when these users last logged on to or logged off from the domain. If users are authenticated by multiple domain controllers, you'll need to install Acctinfo.dll on each of these servers and check the account information on each one.
3. You can unlock a user account using this tab, but you must also change the password to do it.
4. If you click on the "Set PW On Site DC" button, be sure that you do not click the OK button when closing, as you may inadvertently set the user accounts password to blank. Just click Cancel.
5. When using the Find option to locate an account in the AD Users and Computers snap-in, the Additional Info tab does not appear when you display the properties of the account from the search window.
More information on this topic:
Tip: Guide to the Windows Server 2003 Windows Resource Kit Tools
Topics: Admin toolsSign up for our RSS feed to receive expert advice every day.

Wednesday, July 18, 2007

VBS Script To Enumerate Active Directory OU Names And Paths And Send To Excel - Don Hite

VBS Script To Enumerate Active Directory OU Names And Paths And Send To Excel - Don Hite

VBS Script:

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add
intRow = 2

objExcel.Cells(1, 1).Value = "OU Name"
objExcel.Cells(1, 2).Value = "OU Path"

Set objDomain = GetObject("LDAP://RootDSE")
strDomain = objDomain.Get("DefaultNamingContext")

set strOU = GetObject("LDAP://" & strDomain )
strOU.Filter = Array("OrganizationalUnit")

For Each objItem In strOU
arrOU = Split(objItem.Name, "=")
objExcel.Cells(intRow, 1).Value = arrOU(1)
objExcel.Cells(intRow, 2).Value = objItem.AdsPath
intRow = intRow + 1
Next

objExcel.Range("A1:B1").Select
objExcel.Selection.Font.ColorIndex = 11
objExcel.Selection.Font.Bold = True
objExcel.Range("A1:B1").Select
objExcel.Cells.EntireColumn.AutoFit

MsgBox "Done"