diff --git a/AD/CreateN1-N2Users/Create-ADuserFromCsv.ps1 b/AD/CreateN1-N2Users/Create-ADuserFromCsv.ps1 index 02de83b..1d6a722 100644 --- a/AD/CreateN1-N2Users/Create-ADuserFromCsv.ps1 +++ b/AD/CreateN1-N2Users/Create-ADuserFromCsv.ps1 @@ -1,4 +1,6 @@ -# Functions first +Import-Module ActiveDirectory + +# Genpass génere un mdp aléatoire function GenPass { $TokenSet = @{ @@ -21,8 +23,27 @@ function GenPass { } -function New-ADUser { +$userPass = (GenPass) - +$detailsUser = @{ + Name = 'Tech-N1' + AccountPassword = $userPass + Enabled = $true + ChangePasswordAtLogon = $false + PasswordNeverExpires = $true #On fait en sorte qu'il n'expire pas -} \ No newline at end of file +} +New-ADUser @detailsUser #On cree l'user... + +#...puis on l'ajoute aux bons groupes +$User = 'Tech-N1' + +$Groups = @("Account Operators","Print Operators") + +ForEach ($Group in $Groups) { + + Add-ADPrincipalGroupMembership $User -MemberOf $Group + +} + +Write-Host "L'utilisateur $User a bienété cée et ajouté aux groupes 'Account operators' et 'Print Operators'. Son mot de passe est $userPass" \ No newline at end of file