Solved

How to remove spaces of composed lastname ?

Posted on 2013-05-29
10
241 Views
Last Modified: 2013-05-29
Hello,

I have to create AD users from a CSV and would like to know how to remove spaces of a composed last name, for example if an employee's full name is Neymar, Da Silva, then username will be dasilvan

Thanks for your help,
0
Comment
Question by:namerg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
10 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 250 total points
ID: 39205844
"Da Silva" -replace "\s",""
Should give you.. DaSilva

With csv you ca try.. $_.lastname -replace "\s",""
0
 
LVL 19

Assisted Solution

by:Raheman M. Abdul
Raheman M. Abdul earned 250 total points
ID: 39205871
$firstname=" abdul "
$lastname="rahman mohammed"

$firstname=$firstname -replace "\s",""

$lastname=$lastname -replace "\s",""


$username = $lastname+($firstname[0])

--------------------

#Sample output is:

rahmanmohammeda
0
 

Author Comment

by:namerg
ID: 39205885
But, how do i validate it...?
if lastname does not have space
$lastname=$lastname -replace "\s",""  would not matter ?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Expert Comment

by:Raheman M. Abdul
ID: 39205898
does not matter
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39205900
Yes it doesn't matter. If there is no space then you will get the same input string as a result..
0
 

Author Comment

by:namerg
ID: 39205908
Will the following
$LastName = $_."Last Name" -replace "\s"

Open in new window

work ?
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39205915
Yes..

$LastName = $_."Last Name" -replace " "

Will also work..
0
 
LVL 19

Expert Comment

by:Raheman M. Abdul
ID: 39205919
what is $_ representing?
0
 

Author Comment

by:namerg
ID: 39205926
Before:
$sam = $_."Last Name".ToLower() + $_."First Name".substring(0,1).ToLower()
After:
$LastName = $_."Last Name" -replace "\s"
$sam = $LastName.ToLower() + $_."First Name".substring(0,1).ToLower()
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39205943
That should do it..
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Synchronize a new Active Directory domain with an existing Office 365 tenant
A procedure for exporting installed hotfix details of remote computers using powershell
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

752 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