Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

create a user through a file TXT

$
0
0

My script for creating a User:

My problem is in $ SAM, because the "name" attribute in my TXT file is the full name and I would like to create the login User with the first name plus the initials of other names.

example:
Adriano-SA
Adriano Souza Pires

===================================================================== 

Import-Module ActiveDirectory
$Users = Import-Csv -Delimiter ";" -Path "C:\Users\Joan\Documents\Users.txt"  
foreach ($User in $Users)  
{  
    $OU = "OU=SE,DC=icaro,DC=br"  
    $Password = $User.Password
    $Office = $User.Matricula 
    $Detailedname = $User.name 
    $SAM = $User.name.Substring(0,4) + "-" + $Users.Name.Substring(5,1)

    "Criando Usuario: $Detailedname"
        New-ADUser -Name $Detailedname -Office $Office -SamAccountName $SAM -UserPrincipalName $SAM -DisplayName $Detailedname -GivenName $user.Name -Surname $user.Name -AccountPassword (ConvertTo-SecureString $Password -AsPlainText -Force) -Enabled $true -Path $OU  

===================================================

File TXT:

Name;Matricula;Password
Jean Carlos Araujo;99999900;s3nh@senh@
Adriano Souza Pires;99999900;s3nh@senh@



Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>