×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

help with removing space after last name

help with removing space after last name

help with removing space after last name

(OP)
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

RE: help with removing space after last name

(OP)
Never mind, found another attribute to pull and it works as desired.

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

with:

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

-Jeepix

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close