Home » Powershell » Username creation

Username creation

Just give input as first name and last name in inputfile

 

Jeevan bobba

Abcdef ghijklmnopqrst

It will create username and by adding v- at the beginning of username and – in between lastname-firstname

 

CLS
$Users= gc C:\Temp\abcd.txt
$Users | %{
$a = $PSItem
if (($a.Substring(0,2) -like “v-“) -and ($a -notmatch ” “) ){“$a”}
else{
$SamAccountName = ((($a -split ” “)[-1..-5] -join “-“).Insert(0,’z-‘))
#$SamAccountName
#If ($samaccountname.length -ge 19){$samaccountname.remove(19)} else {$SamAccountName}
if ($SamAccountName.length -ge 19){$SamAccountName.substring(0, 19)} else {$SamAccountName}
}
}

Share This:
Facebooktwitter

Leave a Reply

Your email address will not be published. Required fields are marked *

Name *
Email *
Website