Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with removing space after last name

Status
Not open for further replies.

Jeepix

MIS
Aug 21, 2003
102
US
I've pulled this together from some information online and added my own stuff to match my environment, but I'm getting a result that isn't quite what we need. Hoping someone can help!

The output is close, but I can't have a space after the last name:

What I'm getting:
Smith , Jim
Smith , Jane

What I need is:
Smith, Jim
Smith, Jane

Here's my script so far. Thank you in advance for any assistance!!! (the OU information has been changed for security reasons)

Import-Module ActiveDirectory


# All of the expressions you want with all of the filtering .etc you'd like done to them
$expressions=@(
# @{Expression={$_.surName},[char]8,",",{$_.givenName};Label="Name"},
@{Expression={$_.surName,",",$_.givenName};Label="Name"},
@{Expression={$_.emailAddress};Label="Email"}
)

$path_to_file = "C:\temp\Email_Address_Book$((Get-Date).ToString('yyyy-MM-dd_hh-mm-ss')).csv"

'OU=Users,OU=<site1>,OU=D Organization,DC=<domain>,DC=<domain>,DC=COM','OU=Users,OU=<site2>,OU=D Organization,DC=<domain>,DC=<domain>,DC=COM' , 'OU=Users,OU=<site3>,OU=D Organization,DC=<domain>,DC=<domain>,DC=COM' , 'OU=Users,OU=<site4>,OU=D Organization,DC=<domain>,DC=<domain>,DC=COM', 'OU=Users,OU=<site5>,OU=D Organization,DC=<domain>,DC=<domain>,DC=COM' , 'OU=Users,OU=<site6>,OU=D Organization,DC=<domain>,DC=<domain>,DC=COM' | ForEach-Object {

Get-ADUser -Filter 'enabled -eq $true' -SearchBase $_ -Properties *

} | Select $expressions | Export-Csv $path_to_file -NoTypeInformation -Encoding UTF8


Thanks again!!!

-Jeepix
 
Never mind, found another attribute to pull and it works as desired.

replaced:
@{Expression={$_.surName,",",$_.givenName};Label="Name"},

with:

@{Expression={$_.Name};Label="Name"},

-Jeepix
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top