Solved

How to remove spaces of composed lastname ?

Posted on 2013-05-29
10
235 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
  • 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help to build a Proc... 6 30
REGEX to check unique value 1 18
Output to HTML in powershell 3 25
Getting output of invoke command into a combo box 1 12
Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
Set OWA language and time zone in Exchange for individuals, all users or per database.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

839 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