Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to remove spaces of composed lastname ?

Posted on 2013-05-29
10
Medium Priority
?
250 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 1000 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 1000 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
WatchGuard Case Study: NCR

With business operations for thousands of customers largely depending on the internal systems they support, NCR can’t afford to waste time or money on security products that are anything less than exceptional. That’s why they chose WatchGuard.

 
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
In this post, I will showcase the steps for how to create groups in Office 365. Office 365 groups allow for ease of flexibility and collaboration between staff members.
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 anti-spam), the admin…
Screencast - Getting to Know the Pipeline

926 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