49 lines
1.3 KiB
PowerShell
49 lines
1.3 KiB
PowerShell
Import-Module ActiveDirectory
|
|
|
|
# Genpass génere un mdp aléatoire
|
|
function GenPass {
|
|
|
|
$TokenSet = @{
|
|
U = [Char[]]'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
|
L = [Char[]]'abcdefghijklmnopqrstuvwxyz'
|
|
N = [Char[]]'0123456789'
|
|
S = [Char[]]'!"#$%&''()*+,-./:;<=>?@[\]^_`{|}~'
|
|
}
|
|
|
|
$Upper = Get-Random -Count 5 -InputObject $TokenSet.U
|
|
$Lower = Get-Random -Count 5 -InputObject $TokenSet.L
|
|
$Number = Get-Random -Count 5 -InputObject $TokenSet.N
|
|
$Special = Get-Random -Count 5 -InputObject $TokenSet.S
|
|
|
|
$StringSet = $Upper + $Lower + $Number + $Special
|
|
|
|
$RdString = (Get-Random -Count 15 -InputObject $StringSet) -join ''
|
|
|
|
return $RdString
|
|
|
|
}
|
|
|
|
$userPass = (GenPass)
|
|
|
|
$detailsUser = @{
|
|
Name = 'Tech-N1'
|
|
AccountPassword = $userPass
|
|
Enabled = $true
|
|
ChangePasswordAtLogon = $false
|
|
PasswordNeverExpires = $true #On fait en sorte qu'il n'expire pas
|
|
|
|
}
|
|
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" |