Home All Groups Group Topic Archive Search About

How to get accts created in last 7 days



Author
22 Nov 2007 5:41 AM
Wizzy
Hi,

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!!
--
Regards,
Wizzy

Author
22 Nov 2007 5:44 PM
Richard Mueller [MVP]
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,profilePath"



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
--
Author
23 Nov 2007 6:39 AM
Wizzy
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,profilePath"
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


Show quote
"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,profilePath"
>
>
>
> 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
> --
>
>
>
Author
23 Nov 2007 1:51 PM
Richard Mueller [MVP]
Show quote
"Wizzy" <wi***@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,profilePath"
> 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 helps.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--
Author
22 Nov 2007 7:59 PM
Andrew Karmadanov
You can use PowerShell Cmdlets for Active Directory
from here http://www.quest.com/2_0/default.aspx?backtourl=/2_0/registration.aspx?requestdefid=13255

and the following script

######################################33
$Excel = New-Object -com "Excel.Application"
$WorkBook = $Excel.Workbooks.Open("C:\work\1.xls")
$Sheet = $WorkBook.Worksheets.Item("Sheet1")

$OU = "domain.com/enterprise/division/users"
$Date = Date
$Date.AddDays(-7) > $Null

$Users = Get-QADUser -SearchRoot $OU -SearchScope subtree 
-includeallproperties

$n = 1
foreach ($User in $Users)
{
    if ($User.creationdate -gt ([datetime]$Date))
    {
        $Sheet.Cells.Item($n,1).Value2 = $user.displayname
        $Sheet.Cells.Item($n,2).Value2 = $user.creationdate
        $Sheet.Cells.Item($n,3).Value2 = $user.homedirectory
        $Sheet.Cells.Item($n,4).Value2 = $user.profilepath
        $n++
    }
}


$WorkBook.Save()
$WorkBook.Close()
$Excel.Quit()

Andrew

Show quote
"Wizzy" wrote:

> Hi,
>
> 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!!
> --
> Regards,
> Wizzy
Author
24 Nov 2007 3:06 AM
Al Dunbar
And, as an aside, these are not XP accounts, but Active Directory Accounts.

/Al

Show quote
"Andrew Karmadanov" <Andrew Karmada***@discussions.microsoft.com> wrote in
message news:295EFE54-EF08-4C13-A835-CE722050B5B0@microsoft.com...
> You can use PowerShell Cmdlets for Active Directory
> from here
> http://www.quest.com/2_0/default.aspx?backtourl=/2_0/registration.aspx?requestdefid=13255
>
> and the following script
>
> ######################################33
> $Excel = New-Object -com "Excel.Application"
> $WorkBook = $Excel.Workbooks.Open("C:\work\1.xls")
> $Sheet = $WorkBook.Worksheets.Item("Sheet1")
>
> $OU = "domain.com/enterprise/division/users"
> $Date = Date
> $Date.AddDays(-7) > $Null
>
> $Users = Get-QADUser -SearchRoot $OU -SearchScope subtree
> -includeallproperties
>
> $n = 1
> foreach ($User in $Users)
> {
> if ($User.creationdate -gt ([datetime]$Date))
> {
> $Sheet.Cells.Item($n,1).Value2 = $user.displayname
> $Sheet.Cells.Item($n,2).Value2 = $user.creationdate
> $Sheet.Cells.Item($n,3).Value2 = $user.homedirectory
> $Sheet.Cells.Item($n,4).Value2 = $user.profilepath
> $n++
> }
> }
>
>
> $WorkBook.Save()
> $WorkBook.Close()
> $Excel.Quit()
>
> Andrew
>
> "Wizzy" wrote:
>
>> Hi,
>>
>> 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!!
>> --
>> Regards,
>> Wizzy

AddThis Social Bookmark Button