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 > list all users created today
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
list all users created today

Réponse
 
LinkBack Outils de la discussion
Vieux 02/10/2007, 16h29   #1
Simon G
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut list all users created today

Hello all.

I have an ou in which all new users are created. I currently have a script
which will list all the members of the ou and some of their attributes.

What i want to do is to be able to list this, but only for users who have
been created today.

Here is the script i am currently using - how can i include the "where user
was created today" statement?

on error resume next

Const ADS_SCOPE_SUBTREE = 2

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objNewFile = objFS.CreateTextFile("newstarters.csv")

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

objCommand.CommandText = _
"SELECT ADsPath FROM 'LDAP://ou=new starters,,DC=domain,DC=com' WHERE " _
& "objectCategory='user'"
Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst
objnewfile.writeline "samaccountname" & "," & "givenname" & "," & "sn" & ","
& "description"
Do Until objRecordSet.EOF
strPath = objRecordSet.Fields("ADsPath").Value
Set objuser = GetObject(strPath)

objNewFile.WriteLine objuser.samaccountname & "," & objuser.givenname & ","
& objuser.sn & "," & objuser.description
objRecordSet.MoveNext
Loop
  Réponse avec citation
Vieux 02/10/2007, 18h52   #2
Richard Mueller [MVP]
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: list all users created today


"Simon G" <SimonG@discussions.microsoft.com> wrote in message
news:18349334-27A4-4F68-86CF-3393C81E8568@microsoft.com...
> Hello all.
>
> I have an ou in which all new users are created. I currently have a script
> which will list all the members of the ou and some of their attributes.
>
> What i want to do is to be able to list this, but only for users who have
> been created today.
>
> Here is the script i am currently using - how can i include the "where
> user
> was created today" statement?
>
> on error resume next
>
> Const ADS_SCOPE_SUBTREE = 2
>
> Set objConnection = CreateObject("ADODB.Connection")
> Set objCommand = CreateObject("ADODB.Command")
> objConnection.Provider = "ADsDSOObject"
> objConnection.Open "Active Directory Provider"
> Set objCommand.ActiveConnection = objConnection
> Set objFS = CreateObject("Scripting.FileSystemObject")
> Set objNewFile = objFS.CreateTextFile("newstarters.csv")
>
> objCommand.Properties("Page Size") = 1000
> objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
>
> objCommand.CommandText = _
> "SELECT ADsPath FROM 'LDAP://ou=new starters,,DC=domain,DC=com' WHERE "
> _
> & "objectCategory='user'"
> Set objRecordSet = objCommand.Execute
>
> objRecordSet.MoveFirst
> objnewfile.writeline "samaccountname" & "," & "givenname" & "," & "sn" &
> ","
> & "description"
> Do Until objRecordSet.EOF
> strPath = objRecordSet.Fields("ADsPath").Value
> Set objuser = GetObject(strPath)
>
> objNewFile.WriteLine objuser.samaccountname & "," & objuser.givenname &
> ","
> & objuser.sn & "," & objuser.description
> objRecordSet.MoveNext
> Loop


If today is 20071002000000 (yyyymmddhhnnss) then you can use:

"SELECT ADsPath FROM 'LDAP://ou=new starters,DC=domain,DC=com' " _
& " WHERE objectCategory='person' " _
& "AND objectClass='user' " _
& "whenCreated>='20071001000000.0Z'"

I use objectCategory=person and objectClass=user to omit contact objects and
computers. The ".0Z" means UTC, so you may need to adjust for your time
zone. For an offset (differential) of +5 hours, it would be:

"whenCreated>='20071001000000.0+0500'"

The formula is:

GMT=Local+differential

Where GMT is the old acronym for UTC (Coordinated Universal Time in French)
and Local is the local time (in your time zone). Ordinarily these few hours
don't matter, but if you are searching for objects created since midnight,
it can matter.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--


  Réponse avec citation
Vieux 03/10/2007, 09h48   #3
Simon G
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: list all users created today

thanks as always Richard.

Is there anyway that the date can be dynamic, so the script uses some kind
of getdate function, as opposed to me having to amend the date each time.

Failing that, is it possible to have a simple input box appear and the date
is manually entered and then use the varaible in the whencreated >= part
rather than the text?

"Richard Mueller [MVP]" wrote:

>
> "Simon G" <SimonG@discussions.microsoft.com> wrote in message
> news:18349334-27A4-4F68-86CF-3393C81E8568@microsoft.com...
> > Hello all.
> >
> > I have an ou in which all new users are created. I currently have a script
> > which will list all the members of the ou and some of their attributes.
> >
> > What i want to do is to be able to list this, but only for users who have
> > been created today.
> >
> > Here is the script i am currently using - how can i include the "where
> > user
> > was created today" statement?
> >
> > on error resume next
> >
> > Const ADS_SCOPE_SUBTREE = 2
> >
> > Set objConnection = CreateObject("ADODB.Connection")
> > Set objCommand = CreateObject("ADODB.Command")
> > objConnection.Provider = "ADsDSOObject"
> > objConnection.Open "Active Directory Provider"
> > Set objCommand.ActiveConnection = objConnection
> > Set objFS = CreateObject("Scripting.FileSystemObject")
> > Set objNewFile = objFS.CreateTextFile("newstarters.csv")
> >
> > objCommand.Properties("Page Size") = 1000
> > objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
> >
> > objCommand.CommandText = _
> > "SELECT ADsPath FROM 'LDAP://ou=new starters,,DC=domain,DC=com' WHERE "
> > _
> > & "objectCategory='user'"
> > Set objRecordSet = objCommand.Execute
> >
> > objRecordSet.MoveFirst
> > objnewfile.writeline "samaccountname" & "," & "givenname" & "," & "sn" &
> > ","
> > & "description"
> > Do Until objRecordSet.EOF
> > strPath = objRecordSet.Fields("ADsPath").Value
> > Set objuser = GetObject(strPath)
> >
> > objNewFile.WriteLine objuser.samaccountname & "," & objuser.givenname &
> > ","
> > & objuser.sn & "," & objuser.description
> > objRecordSet.MoveNext
> > Loop

>
> If today is 20071002000000 (yyyymmddhhnnss) then you can use:
>
> "SELECT ADsPath FROM 'LDAP://ou=new starters,DC=domain,DC=com' " _
> & " WHERE objectCategory='person' " _
> & "AND objectClass='user' " _
> & "whenCreated>='20071001000000.0Z'"
>
> I use objectCategory=person and objectClass=user to omit contact objects and
> computers. The ".0Z" means UTC, so you may need to adjust for your time
> zone. For an offset (differential) of +5 hours, it would be:
>
> "whenCreated>='20071001000000.0+0500'"
>
> The formula is:
>
> GMT=Local+differential
>
> Where GMT is the old acronym for UTC (Coordinated Universal Time in French)
> and Local is the local time (in your time zone). Ordinarily these few hours
> don't matter, but if you are searching for objects created since midnight,
> it can matter.
>
> --
> Richard Mueller
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
> --
>
>
>

  Réponse avec citation
Vieux 03/10/2007, 13h28   #4
Richard Mueller [MVP]
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: list all users created today

Takes a bit of work to construct the date in the correct format, but below
should work:
============
dtmToday = Date()
dtmYesterday = DateAdd("d", dtmToday, -1)

strYear = CStr(Year(dtmYesterday))
strMonth = Right("0" & CStr(Month(dtmYesterday)), 2)
strDay = Right("0" & CStr(Day(dtmYesterday)), 2)
strYesterday = strYear & strMonth & strDay & "000000.Z"

objCommand.CommandText = _
"SELECT ADsPath FROM 'LDAP://ou=new starters,DC=domain,DC=com' " _
& " WHERE objectCategory='person' " _
& "AND objectClass='user' " _
& "AND whenCreated>='" & strYesterday & "'"
================
In my previous post, I believe I missed the second "AND" in the "WHERE"
clause above.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--

"Simon G" <SimonG@discussions.microsoft.com> wrote in message
news:7B41E6CB-A9DD-4315-9AD0-94D0BABC87B7@microsoft.com...
> thanks as always Richard.
>
> Is there anyway that the date can be dynamic, so the script uses some kind
> of getdate function, as opposed to me having to amend the date each time.
>
> Failing that, is it possible to have a simple input box appear and the
> date
> is manually entered and then use the varaible in the whencreated >= part
> rather than the text?
>
> "Richard Mueller [MVP]" wrote:
>
>>
>> "Simon G" <SimonG@discussions.microsoft.com> wrote in message
>> news:18349334-27A4-4F68-86CF-3393C81E8568@microsoft.com...
>> > Hello all.
>> >
>> > I have an ou in which all new users are created. I currently have a
>> > script
>> > which will list all the members of the ou and some of their attributes.
>> >
>> > What i want to do is to be able to list this, but only for users who
>> > have
>> > been created today.
>> >
>> > Here is the script i am currently using - how can i include the "where
>> > user
>> > was created today" statement?
>> >
>> > on error resume next
>> >
>> > Const ADS_SCOPE_SUBTREE = 2
>> >
>> > Set objConnection = CreateObject("ADODB.Connection")
>> > Set objCommand = CreateObject("ADODB.Command")
>> > objConnection.Provider = "ADsDSOObject"
>> > objConnection.Open "Active Directory Provider"
>> > Set objCommand.ActiveConnection = objConnection
>> > Set objFS = CreateObject("Scripting.FileSystemObject")
>> > Set objNewFile = objFS.CreateTextFile("newstarters.csv")
>> >
>> > objCommand.Properties("Page Size") = 1000
>> > objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
>> >
>> > objCommand.CommandText = _
>> > "SELECT ADsPath FROM 'LDAP://ou=new starters,,DC=domain,DC=com'
>> > WHERE "
>> > _
>> > & "objectCategory='user'"
>> > Set objRecordSet = objCommand.Execute
>> >
>> > objRecordSet.MoveFirst
>> > objnewfile.writeline "samaccountname" & "," & "givenname" & "," & "sn"
>> > &
>> > ","
>> > & "description"
>> > Do Until objRecordSet.EOF
>> > strPath = objRecordSet.Fields("ADsPath").Value
>> > Set objuser = GetObject(strPath)
>> >
>> > objNewFile.WriteLine objuser.samaccountname & "," & objuser.givenname &
>> > ","
>> > & objuser.sn & "," & objuser.description
>> > objRecordSet.MoveNext
>> > Loop

>>
>> If today is 20071002000000 (yyyymmddhhnnss) then you can use:
>>
>> "SELECT ADsPath FROM 'LDAP://ou=new starters,DC=domain,DC=com' " _
>> & " WHERE objectCategory='person' " _
>> & "AND objectClass='user' " _
>> & "whenCreated>='20071001000000.0Z'"
>>
>> I use objectCategory=person and objectClass=user to omit contact objects
>> and
>> computers. The ".0Z" means UTC, so you may need to adjust for your time
>> zone. For an offset (differential) of +5 hours, it would be:
>>
>> "whenCreated>='20071001000000.0+0500'"
>>
>> The formula is:
>>
>> GMT=Local+differential
>>
>> Where GMT is the old acronym for UTC (Coordinated Universal Time in
>> French)
>> and Local is the local time (in your time zone). Ordinarily these few
>> hours
>> don't matter, but if you are searching for objects created since
>> midnight,
>> it can matter.
>>
>> --
>> Richard Mueller
>> Microsoft MVP Scripting and ADSI
>> Hilltop Lab - http://www.rlmueller.net
>> --
>>
>>
>>



  Réponse avec citation
Vieux 03/10/2007, 15h59   #5
Simon G
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: list all users created today

fantastic, works a treat.

thanks again

"Richard Mueller [MVP]" wrote:

> Takes a bit of work to construct the date in the correct format, but below
> should work:
> ============
> dtmToday = Date()
> dtmYesterday = DateAdd("d", dtmToday, -1)
>
> strYear = CStr(Year(dtmYesterday))
> strMonth = Right("0" & CStr(Month(dtmYesterday)), 2)
> strDay = Right("0" & CStr(Day(dtmYesterday)), 2)
> strYesterday = strYear & strMonth & strDay & "000000.Z"
>
> objCommand.CommandText = _
> "SELECT ADsPath FROM 'LDAP://ou=new starters,DC=domain,DC=com' " _
> & " WHERE objectCategory='person' " _
> & "AND objectClass='user' " _
> & "AND whenCreated>='" & strYesterday & "'"
> ================
> In my previous post, I believe I missed the second "AND" in the "WHERE"
> clause above.
>
> --
> Richard Mueller
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
> --
>
> "Simon G" <SimonG@discussions.microsoft.com> wrote in message
> news:7B41E6CB-A9DD-4315-9AD0-94D0BABC87B7@microsoft.com...
> > thanks as always Richard.
> >
> > Is there anyway that the date can be dynamic, so the script uses some kind
> > of getdate function, as opposed to me having to amend the date each time.
> >
> > Failing that, is it possible to have a simple input box appear and the
> > date
> > is manually entered and then use the varaible in the whencreated >= part
> > rather than the text?
> >
> > "Richard Mueller [MVP]" wrote:
> >
> >>
> >> "Simon G" <SimonG@discussions.microsoft.com> wrote in message
> >> news:18349334-27A4-4F68-86CF-3393C81E8568@microsoft.com...
> >> > Hello all.
> >> >
> >> > I have an ou in which all new users are created. I currently have a
> >> > script
> >> > which will list all the members of the ou and some of their attributes.
> >> >
> >> > What i want to do is to be able to list this, but only for users who
> >> > have
> >> > been created today.
> >> >
> >> > Here is the script i am currently using - how can i include the "where
> >> > user
> >> > was created today" statement?
> >> >
> >> > on error resume next
> >> >
> >> > Const ADS_SCOPE_SUBTREE = 2
> >> >
> >> > Set objConnection = CreateObject("ADODB.Connection")
> >> > Set objCommand = CreateObject("ADODB.Command")
> >> > objConnection.Provider = "ADsDSOObject"
> >> > objConnection.Open "Active Directory Provider"
> >> > Set objCommand.ActiveConnection = objConnection
> >> > Set objFS = CreateObject("Scripting.FileSystemObject")
> >> > Set objNewFile = objFS.CreateTextFile("newstarters.csv")
> >> >
> >> > objCommand.Properties("Page Size") = 1000
> >> > objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
> >> >
> >> > objCommand.CommandText = _
> >> > "SELECT ADsPath FROM 'LDAP://ou=new starters,,DC=domain,DC=com'
> >> > WHERE "
> >> > _
> >> > & "objectCategory='user'"
> >> > Set objRecordSet = objCommand.Execute
> >> >
> >> > objRecordSet.MoveFirst
> >> > objnewfile.writeline "samaccountname" & "," & "givenname" & "," & "sn"
> >> > &
> >> > ","
> >> > & "description"
> >> > Do Until objRecordSet.EOF
> >> > strPath = objRecordSet.Fields("ADsPath").Value
> >> > Set objuser = GetObject(strPath)
> >> >
> >> > objNewFile.WriteLine objuser.samaccountname & "," & objuser.givenname &
> >> > ","
> >> > & objuser.sn & "," & objuser.description
> >> > objRecordSet.MoveNext
> >> > Loop
> >>
> >> If today is 20071002000000 (yyyymmddhhnnss) then you can use:
> >>
> >> "SELECT ADsPath FROM 'LDAP://ou=new starters,DC=domain,DC=com' " _
> >> & " WHERE objectCategory='person' " _
> >> & "AND objectClass='user' " _
> >> & "whenCreated>='20071001000000.0Z'"
> >>
> >> I use objectCategory=person and objectClass=user to omit contact objects
> >> and
> >> computers. The ".0Z" means UTC, so you may need to adjust for your time
> >> zone. For an offset (differential) of +5 hours, it would be:
> >>
> >> "whenCreated>='20071001000000.0+0500'"
> >>
> >> The formula is:
> >>
> >> GMT=Local+differential
> >>
> >> Where GMT is the old acronym for UTC (Coordinated Universal Time in
> >> French)
> >> and Local is the local time (in your time zone). Ordinarily these few
> >> hours
> >> don't matter, but if you are searching for objects created since
> >> midnight,
> >> it can matter.
> >>
> >> --
> >> 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 19h48.


Édité par : vBulletin® version 3.7.2
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
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,22945 seconds with 13 queries