Solved

How can i produce a csv fie with username ,First name , Last Name , Full name and Email address from SBS 2008 ?

Posted on 2016-10-17
4
36 Views
Last Modified: 2016-10-18
I know that its possible to do this with powershell but I cant run active directory module on SBS 2008 .
0
Comment
Question by:Andre P
  • 2
4 Comments
 
LVL 80

Expert Comment

by:David Johnson, CD, MVP
ID: 41847648
one way is to install
Active Directory Management Gateway Service or the Quest Powershell Tools
    64-bit version: Quest ActiveRolesManagementShellforActiveDirectoryx64 151.zip
    32-bit version: Quest ActiveRolesManagementShellforActiveDirectoryx86 151.zip
Installation walkthrough: http://www.powershelladmin.com/wiki/Quest_ActiveRoles_Management_Shell_Download
0
 
LVL 84

Accepted Solution

by:
oBdA earned 500 total points
ID: 41847720
Powershell without the need for external tools:
Function Get-ADSIUser {
[CmdletBinding()]
Param(
	[string]$SamAccountName = '*',
	[string[]]$AttributeList = @()
)
	If ($AttributeList.Count -eq 0) {
		$AttributeList = @(
			'createTimeStamp'
			'displayName'
			'distinguishedName'
			'givenName'
			'name'
			'sAMAccountName'
			'sn'
			'userPrincipalName'
		)
	}
	Try {
		$RootDSE = [ADSI]'LDAP://RootDSE'
		$ADODBConnection = New-Object -ComObject 'ADODB.Connection'
		$ADODBConnection.Provider = 'ADsDSOObject'
		$ADODBConnection.Open('Active Directory Provider')
		$ADODBCommand = New-Object -ComObject 'ADODB.Command'
		$ADODBCommand.ActiveConnection = $ADODBConnection
		$BaseDN = "LDAP://$($RootDSE.defaultNamingContext)"
		$Filter = "(&(objectCategory=person)(objectClass=user)(samaccountname=$($SamAccountName)))"
		$ADODBCommand.CommandText = "<" + $BaseDN + ">;" + $Filter + ";" + ($AttributeList -Join ",") + ";subtree"
		$ADODBCommand.Properties.Item('Page Size').Value = 1000
		$ADODBCommand.Properties.Item('Size Limit').Value = 10000
		$ADODBCommand.Properties.Item('Timeout').Value = 60
		$ADODBCommand.Properties.Item('Cache Results').Value = $False
		$RecordSet = $ADODBCommand.Execute()
		If ($RecordSet.EOF) {
			"User '$($SamAccountName)' not found!" | Write-Warning
		} Else {
			Do {
				$ADUser = '' | Select-Object -Property $AttributeList
				ForEach ($Attribute In $AttributeList) {
					$ADUser.$Attribute = $RecordSet.Fields.Item($Attribute).Value
				}
				$ADUser
				$RecordSet.MoveNext()
			} Until ($RecordSet.EOF)
		}
	} Catch {
		Throw $_
	} Finally {
		If ($RecordSet) {$RecordSet.Close()}
		If ($ADODBCommand) {[Runtime.InteropServices.Marshal]::FinalReleaseComObject($ADODBCommand) | Out-Null}
		If ($ADODBConnection) {
			$ADODBConnection.Close()
			[Runtime.InteropServices.Marshal]::FinalReleaseComObject($ADODBConnection) | Out-Null
		}
	}
}

Get-ADSIUser | Select-Object samAccountName, displayName, givenName, sn, createTimeStamp | Sort-Object samAccountName | Export-Csv -NoTypeInformation -Path C:\users_list.csv

Open in new window

1
 
LVL 8

Expert Comment

by:Antzs
ID: 41847798
Take a look at the below.

https://www.experts-exchange.com/questions/28958687/Need-help-with-an-PowerShell-command-to-extract-user-attributes.html

You don't have to run it on the server.  It can be run from any PC joined to the domain.
0
 
LVL 84

Expert Comment

by:oBdA
ID: 41848002
Sorry, forgot the mail.
Just add a new line 13 with 'mail' to the attributes retrieved.
Then in the last line, add the property to Select-Object, for example like this:
Get-ADSIUser | Select-Object samAccountName, displayName, givenName, sn, mail | Export-Csv -NoTypeInformation -Path C:\users_list.csv

Open in new window

0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article outlines the process to identify and resolve account lockout in an Active Directory environment.
Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question