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

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 83

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 5

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 83

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
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 configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

705 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now