Solved

How to remove spaces of composed lastname ?

Posted on 2013-05-29
10
242 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
Ready to trade in that old firewall?

Whether you need to trade-up to a shiny new Firebox or just ready to upgrade from whatever appliance you're using now, WatchGuard has the right appliance for you! Find your perfect Firebox today with appliance sizing tool!

 
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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

632 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