Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $quit = 'O'
- $password = 'P@$$w0rd'
- $password = ConvertTo-SecureString $pswd -AsPlainText -Force
- do
- {
- $surname = Read-Host "Entrez le nom de l'utilisateur: "
- $givenname = Read-Host "Entrez le prenom de l'utilisateur: "
- $service = Read-Host "Entre le nom du service: "
- $name = $givenname + " " + $surname
- $usrprincipalname = $givenname[0] + "." + $surname
- $filter = "*$service"
- New-ADUser -Name $name -Surname $surname -GivenName $givenname -SamAccountName $usrprincipalname -UserPrincipalName $usrprincipalname -AccountPassword $password -CannotChangePassword $false -ChangePasswordAtLogon $True -PasswordNeverExpires $false –Enable $true -Path "OU=TEST,DC=fod,DC=comb"
- If (Get-ADGroup -Filter {(Name -like $filter) -and (DisplayName -eq $filter) -and (GroupCategory -eq "Security") -and (GroupScope -eq "Global")} )
- {
- Add-ADGroupMember -Members $name -Identity GG_$service
- }
- Else
- {
- $filter = "*$service*"
- if ((Get-ADGroup -Filter {Name -like $filter}).count -eq 0)
- {
- $group = 'GG_'+$service
- C:\Users\Administrateur\Documents\PowerShell\exo16bis.ps1
- Add-ADGroupMember -Identity $group -Members $name
- }
- else
- {
- (Get-ADGroup -Filter {Name -like $filter}).Name | Write-Host
- $group = Read-Host "Dans quel groupe doit etre l'utilisateur: "
- if ($group -eq '')
- {
- Read-Host "Aucun groupe selectionne..."
- $quit = $true
- }
- Add-ADGroupMember -Identity $group -Members $name
- }
- }
- $quit = Read-Host "Souhaitez-vous continuez? O/N"
- }
- While ($quit -eq 'O')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement