PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > ms.win.server.scripting > Re: How to get accts created in last 7 days
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Re: How to get accts created in last 7 days

Réponse
 
LinkBack Outils de la discussion
Vieux 22/11/2007, 18h44   #1
Richard Mueller [MVP]
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to get accts created in last 7 days

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
--


  Réponse avec citation
Vieux 23/11/2007, 07h39   #2
Wizzy
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to get accts created in last 7 days

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
> --
>
>
>

  Réponse avec citation
Vieux 23/11/2007, 14h51   #3
Richard Mueller [MVP]
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to get accts created in last 7 days


"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
--


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 02h46.


Édité par : vBulletin® version 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,18325 seconds with 11 queries