|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Wizzy wrote:
> > I would like to know how to get a list of xp accts created in an OU in > past > 7 days along with their creation date, home drive path & profile path. I > would like the output of the script to be directed to an excel file with > each > type of attribute in different coumns. Kindly advise!! You can use ADO in a VBScript program for this. See this link: http://www.rlmueller.net/ADOSearchTips.htm If today is Nov. 22, 2007, and you want all users created since Nov 17, the search filter would be: strFilter = "(&(objectCategory=person)(objectClass=user)" _ & "(whenCreated>=20071117000000.0Z))" The format for the date is yyyymmddhhmmss.0z. You specify the attribute values to retrieve in a comma delimited list: strAttributes = "sAMAccountName,whenCreated,homeDirectory,profileP ath" To restrict the search to an OU, specify the Distinguished Name of the OU as the base of the search: strBase = "<LDAP://ou=Sales,ou=West,dc=MyDomain,dc=com>" Run the script at a command prompt with the cscript host. You can use the //nologo option to suppress logo information. You can redirect the output to a text file. You can use Wscript.Echo statements to output one line per user, with values delimited with commas. This resulting file can be read by Excel. You can also use the filter above with command line tools like adfind. This tool can output directly to a csv. http://joeware.net/freetools/tools/adfind/index.htm Probably other command line tools can also be used. -- Richard Mueller Microsoft MVP Scripting and ADSI Hilltop Lab - http://www.rlmueller.net -- |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
Hi Rich & Andrew,
I attempted to use the below script however I get the error as "H:\Accts.vbs(33, 5) ADODB.Recordset: Item cannot be found in the collection corr esponding to the requested name or ordinal." ---------------------------------------------------------------------------- Option Explicit Dim adoCommand, adoConnection, strBase, strFilter, strAttributes Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strName, strCN Set adoCommand = CreateObject("ADODB.Command") Set adoConnection = CreateObject("ADODB.Connection") adoConnection.Provider = "ADsDSOObject" adoConnection.Open "Active Directory Provider" adoCommand.ActiveConnection = adoConnection Set objRootDSE = GetObject("LDAP://RootDSE") strDNSDomain = objRootDSE.Get("defaultNamingContext") strBase = "<LDAP://ou=Sales,ou=West,dc=MyDomain,dc=com>" strFilter = "(&(objectCategory=person)(objectClass=user)" _ & "(whenCreated>=20071117000000.0Z))" strAttributes = "sAMAccountName,whenCreated,homeDirectory,profileP ath" strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree" adoCommand.CommandText = strQuery adoCommand.Properties("Page Size") = 100 adoCommand.Properties("Timeout") = 30 adoCommand.Properties("Cache Results") = False Set adoRecordset = adoCommand.Execute Do Until adoRecordset.EOF strName = adoRecordset.Fields("sAMAccountName").Value strCN = adoRecordset.Fields("cn").value Wscript.Echo "NT Name: " & strName & ", Common Name: " & strCN adoRecordset.MoveNext Loop ' Clean up. adoRecordset.Close adoConnection.Close --------------------------------------------------------------- -- Regards, Wizzy "Richard Mueller [MVP]" wrote: > Wizzy wrote: > > > > > I would like to know how to get a list of xp accts created in an OU in > > past > > 7 days along with their creation date, home drive path & profile path. I > > would like the output of the script to be directed to an excel file with > > each > > type of attribute in different coumns. Kindly advise!! > > You can use ADO in a VBScript program for this. See this link: > > http://www.rlmueller.net/ADOSearchTips.htm > > If today is Nov. 22, 2007, and you want all users created since Nov 17, the > search filter would be: > > strFilter = "(&(objectCategory=person)(objectClass=user)" _ > & "(whenCreated>=20071117000000.0Z))" > > > > The format for the date is yyyymmddhhmmss.0z. You specify the attribute > values to retrieve in a comma delimited list: > > > > strAttributes = "sAMAccountName,whenCreated,homeDirectory,profileP ath" > > > > To restrict the search to an OU, specify the Distinguished Name of the OU as > the base of the search: > > > > strBase = "<LDAP://ou=Sales,ou=West,dc=MyDomain,dc=com>" > > > > Run the script at a command prompt with the cscript host. You can use the > //nologo option to suppress logo information. You can redirect the output to > a text file. You can use Wscript.Echo statements to output one line per > user, with values delimited with commas. This resulting file can be read by > Excel. > > > > You can also use the filter above with command line tools like adfind. This > tool can output directly to a csv. > > > > http://joeware.net/freetools/tools/adfind/index.htm > > > > Probably other command line tools can also be used. > > > -- > Richard Mueller > Microsoft MVP Scripting and ADSI > Hilltop Lab - http://www.rlmueller.net > -- > > > |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
"Wizzy" <wizzy@techie.com> wrote in message news:F2D9D447-1CE2-4411-A25B-5FC04142F1F0@microsoft.com... > Hi Rich & Andrew, > > I attempted to use the below script however I get the error as > "H:\Accts.vbs(33, 5) ADODB.Recordset: Item cannot be found in the > collection > corr > esponding to the requested name or ordinal." > ---------------------------------------------------------------------------- > Option Explicit > > Dim adoCommand, adoConnection, strBase, strFilter, strAttributes > > Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strName, strCN > > Set adoCommand = CreateObject("ADODB.Command") > Set adoConnection = CreateObject("ADODB.Connection") > adoConnection.Provider = "ADsDSOObject" > adoConnection.Open "Active Directory Provider" > adoCommand.ActiveConnection = adoConnection > > Set objRootDSE = GetObject("LDAP://RootDSE") > > strDNSDomain = objRootDSE.Get("defaultNamingContext") > strBase = "<LDAP://ou=Sales,ou=West,dc=MyDomain,dc=com>" > strFilter = "(&(objectCategory=person)(objectClass=user)" _ > & "(whenCreated>=20071117000000.0Z))" > > strAttributes = "sAMAccountName,whenCreated,homeDirectory,profileP ath" > strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree" > > adoCommand.CommandText = strQuery > adoCommand.Properties("Page Size") = 100 > adoCommand.Properties("Timeout") = 30 > adoCommand.Properties("Cache Results") = False > Set adoRecordset = adoCommand.Execute > > Do Until adoRecordset.EOF > > strName = adoRecordset.Fields("sAMAccountName").Value > > strCN = adoRecordset.Fields("cn").value > > Wscript.Echo "NT Name: " & strName & ", Common Name: " & strCN > > adoRecordset.MoveNext > Loop > > ' Clean up. > > adoRecordset.Close > > adoConnection.Close > --------------------------------------------------------------- > > -- > Regards, > Wizzy > In the loop you attempt to retrieve the value of the "cn" attribute, but that is not in the list of attributes requested. The loop should be similar to: =================== Dim strNTName, strWhenCreated, strHomeDir, strProfile Do Until adoRecordset.EOF ' Retrieve attribute values for this user. strNTName = adoRecordset.Fields("sAMAccountName").Value strWhenCreated = adoRecordset.Fields("whenCreated").value strHomeDir = adoRecordset.Fields("homeDirectory").Value strProfile = adoRecordset.Fields("profilePath").Value ' Output the values, comma delimited. Wscript.Echo strNTName & "," & strWhenCreated _ & "," & strHomeDir & "," & strHomeDir & "," & strProfile ' Move to the next record. adoRecordset.MoveNext Loop =============== This retrieves the values of each attribute requested, assigns the value to a variable, then outputs all of the values in a comma delimited line. I also declared the new variables in a Dim statement, since the script uses Option Explicit. I hope this s. -- Richard Mueller Microsoft MVP Scripting and ADSI Hilltop Lab - http://www.rlmueller.net -- |
|
![]() |
| Outils de la discussion | |
|
|