Link to home
Start Free TrialLog in
Avatar of namerg
namergFlag for United States of America

asked on

How to remove spaces of composed lastname ?

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,
ASKER CERTIFIED SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of namerg

ASKER

But, how do i validate it...?
if lastname does not have space
$lastname=$lastname -replace "\s",""  would not matter ?
does not matter
Yes it doesn't matter. If there is no space then you will get the same input string as a result..
Avatar of namerg

ASKER

Will the following
$LastName = $_."Last Name" -replace "\s"

Open in new window

work ?
Yes..

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

Will also work..
what is $_ representing?
Avatar of namerg

ASKER

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()
That should do it..