Active Directory: User Info

If you need some information from a user account you can use this script.

user_info.ps1

#create table
$tabName = "users"
$table = New-Object system.Data.DataTable "$tabName"

#create columns
$name = New-Object system.Data.DataColumn name,([string])
$title = New-Object system.Data.DataColumn title,([string])
$department = New-Object system.Data.DataColumn department,([string])
$company = New-Object system.Data.DataColumn company,([string])
$telephonenumber = New-Object system.Data.DataColumn telephonenumber,([string])
$mobile = New-Object system.Data.DataColumn mobile,([string])
$whencreated = New-Object system.Data.DataColumn whencreated,([string])
$lastpwdchange = New-Object system.Data.DataColumn lastpwdchange,([string])
$lastlogon = New-Object system.Data.DataColumn lastlogon,([string])
$homedirectory = New-Object system.Data.DataColumn homedirectory,([string])
$manager = New-Object system.Data.DataColumn manager,([string])
$table.columns.add($name)
$table.columns.add($title)
$table.columns.add($department)
$table.columns.add($company)
$table.columns.add($telephonenumber)
$table.columns.add($mobile)
$table.columns.add($whencreated)
$table.columns.add($lastpwdchange)
$table.columns.add($lastlogon)
$table.columns.add($homedirectory)
$table.columns.add($manager)

foreach ($arg in $args)
{
   #create new row
   $row = $table.NewRow()

   #fetch information
   $searcher=New-Object DirectoryServices.DirectorySearcher
   $searcher.Filter="(&(samaccountname=$arg))"
   $results=$searcher.findone()

   $row.name = $results.properties.displayname[0]
   $row.title = $results.properties.title[0]
   $row.department = $results.properties.department[0]
   $row.company = $results.properties.company[0]
   $row.telephonenumber = $results.properties.telephonenumber[0]
   $row.mobile = $results.properties.mobile[0]
   $row.whencreated = $results.properties.whencreated[0]
   $row.lastpwdchange = [datetime]::fromfiletime($results.properties.pwdlastset[0])
   $row.lastlogon = [datetime]::fromfiletime($results.properties.lastlogon[0])
   $row.homedirectory = $results.properties.homedirectory[0]
   $row.manager = $results.properties.manager[0]

   $table.Rows.Add($row)
}
$table | format-list

To use this script open up a powershell comman prompt and start it.
You can pass one or more usernames to it.

.\user_info.ps1 username1 username2
Tagged ,