Solved

How to remove spaces of composed lastname ?

Posted on 2013-05-29
10
226 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 18

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
 
LVL 18

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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 18

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Set OWA language and time zone in Exchange for individuals, all users or per database.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now