Advertisement
Combreal

usersgroups.ps1

Aug 18th, 2017
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $quit = 'O'
  2. $password = 'P@$$w0rd'
  3. $password = ConvertTo-SecureString $pswd -AsPlainText -Force
  4. do
  5. {    
  6.     $surname = Read-Host "Entrez le nom de l'utilisateur: "
  7.     $givenname = Read-Host "Entrez le prenom de l'utilisateur: "
  8.     $service = Read-Host "Entre le nom du service: "
  9.     $name = $givenname + " " + $surname
  10.     $usrprincipalname = $givenname[0] + "." + $surname
  11.     $filter = "*$service"    
  12.     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"
  13.     If (Get-ADGroup -Filter {(Name -like $filter) -and (DisplayName -eq $filter) -and (GroupCategory -eq "Security") -and (GroupScope -eq "Global")} )
  14.     {
  15.         Add-ADGroupMember -Members $name -Identity GG_$service
  16.     }
  17.     Else
  18.     {
  19.         $filter = "*$service*"
  20.         if ((Get-ADGroup -Filter {Name -like $filter}).count -eq 0)
  21.         {
  22.             $group = 'GG_'+$service
  23.             C:\Users\Administrateur\Documents\PowerShell\exo16bis.ps1
  24.             Add-ADGroupMember -Identity $group -Members $name
  25.         }
  26.         else
  27.         {
  28.             (Get-ADGroup -Filter {Name -like $filter}).Name | Write-Host
  29.             $group = Read-Host "Dans quel groupe doit etre l'utilisateur: "
  30.             if ($group -eq '')
  31.             {
  32.                 Read-Host "Aucun groupe selectionne..."
  33.                 $quit = $true
  34.             }
  35.             Add-ADGroupMember -Identity $group -Members $name
  36.         }
  37.     }
  38.     $quit = Read-Host "Souhaitez-vous continuez? O/N"
  39. }
  40. While ($quit -eq 'O')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement