Link to home
Create AccountLog in
Avatar of namerg
namergFlag for United States of America

asked on

How to export AD Users into a CSV that does not have an employee number

How to export AD Users into a CSV that does not have an employee number?

I do have the following code but the csv comes weird, I would like to have the samaccount, name, lastname etc,etc, Thanks for your help

$Ad = Get-ADUser -SearchBase "OU=OUi,DC=company,DC=com"  -Filter * -Properties employeeNumber | ? {(-not($_.employeenumber))}
$Ad | Sort-Object -Property sn, givenName | Select * | Export-Csv c:\scripts\ceridian\NoClockNumber_2013_02_12.csv -NoTypeInformation

Open in new window

Avatar of Sarang Tinguria
Sarang Tinguria
Flag of India image

You may use ADInfo and under user search you will find exactly the same thing what you are looking for
Run the Search "User with specified employee ID "
and select option "No Value" and select additional attributes

 AD Info - Active Directory Reporting
www.cjwdev.co.uk/Software/ADReportingTool/Info.html
Avatar of namerg

ASKER

I am looking for a Powershell code.
SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Hi this is the code that i figured out what i enter i get. Look if it helps you out in any of the cases...

Here it is in case it might be useful to somebody else.

$alist = "Name`tAccountName`tDescription`tEmailAddress`tLastLogonDate`tManager`tTitle`tDepartment`tCompany`twhenCreated`tAcctEnabled`tGroups`n"
$userlist = Get-ADUser -Filter * -Properties * | Select-Object -Property Name,SamAccountName,Description,EmailAddress,LastLogonDate,Manager,Title,Department,Company,whenCreated,Enabled,MemberOf | Sort-Object -Property Name
$userlist | ForEach-Object {
    $grps = $_.MemberOf | Get-ADGroup | ForEach-Object {$_.Name} | Sort-Object
    $arec = $_.Name,$_.SamAccountName,$_.Description,$_.EmailAddress,$_LastLogonDate,$_.Manager,$_.Title,$_.Department,$_.Company,$_.whenCreated,$_.Enabled
    $aline = ($arec -join "`t") + "`t" + ($grps -join "`t") + "`n"
    $alist += $aline
}
$alist | Out-File D:\Temp\ADUsers.csv

Hope it helps you.

Thanks.
Avatar of namerg

ASKER

@Subsun: Almost 100%
@jeorge, got an error.

Subsun, namaste.

Why do I get the following extra columns ?
DistinguishedName	EmployeeNumber	Enabled	GivenName	Name	ObjectClass	ObjectGUID	SamAccountName	SID	sn	Surname	UserPrincipalName	PropertyNames	PropertyCount

Open in new window

I just need EmployeeNumber, GivenName, Name, SamAccountName, Surname and UserPincipalName or Email

I did try the 2nd option.

Thanks for your help,
G
ASKER CERTIFIED SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of namerg

ASKER

You da man :) Thank you very much.