Quantcast
Channel: Software Communities: Message List - Unique Name Generation for Quick Connect based on counter?
Viewing all articles
Browse latest Browse all 9

Re: Unique Name Generation for Quick Connect based on counter?

$
0
0

Victoria/Greg:

 

Thanks for the help.  You gave me the clues I needed.  While probably not the cleanest way to do this it works.  I'll work on neatness and efficiency in the future!

 


Add-Pssnapin Quest.ActiveRoles.ADManagement -ErrorAction SilentlyContinue
#Add-PSSnapin Microsoft.PowerShell.Core -ErrorAction SilentlyContinue

#Generate base account name of up to 8 characters in lowercase from CSV file removing spaces, commas and apostrophes

$Firstname = $SrcObj["First Name"].ToLower()
$Lastname = $SrcObj["Last Name"].ToLower().replace("-","").replace("'","").replace(" ","")

  If ($Lastname.length -ge 8) {$UserName=$Lastname.substring(0,7)+$Firstname.substring(0,1)}
   If ($LastName.length -le 7) {$UserName=$LastName+$Firstname.substring(0,1)}

#Search for Uniqueness in Domain

$Source = "DC=blah,DC=blah,DC=blah,DC=com"
#$Source = "DC=blue,DC=blue,DC=blue,DC=com"
$Name = $UserName
$defaultname= $UserName
$Exit= 0
$Count=1
Do
{
       # Attempt to retrieve information on the user.
        $User = $null
        $User = (Get-QADUser -SearchRoot $Source -proxy -DontUseDefaultIncludedProperties -objectAttributes @{samaccountname=$Name}).samaccountname
         If ($User -ne $null) {$Name = $defaultname + $Count++}
         Else {$Exit = 1 }

         If (($name.length -eq 9) -and ($Lastname.length -ge 7)) {$name = $Lastname.substring(0,6)+$Firstname.substring(0,1) + $Count}
         If (($name.length -eq 10) -and ($Lastname.length -ge 7)) {$name = $Lastname.substring(0,5)+$Firstname.substring(0,1) + $Count}
         If (($name.length -eq 11) -and ($Lastname.length -ge 7)) {$name = $Lastname.substring(0,4)+$Firstname.substring(0,1) + $Count}
         If (($name.length -eq 9) -and ($Lastname.length -eq 6)) {$name = $Lastname.substring(0,5)+$Firstname.substring(0,1) + $Count}
         If (($name.length -eq 10) -and ($Lastname.length -eq 6)) {$name = $Lastname.substring(0,4)+$Firstname.substring(0,1) + $Count}
         If (($name.length -eq 9) -and ($Lastname.length -eq 5)) {$name = $Lastname.substring(0,4)+$Firstname.substring(0,1) + $Count}
 
}
While ($Exit -eq 0)
$Name


Viewing all articles
Browse latest Browse all 9

Latest Images

Trending Articles





Latest Images