Advertisement
Guest User

Untitled

a guest
Apr 15th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #tworzenie grup
  2. $arr = @('GG - Sales','GG - Finance','GG - Informatics')  | ForEach-Object {New-ADGroup -Name $_  -GroupCategory Security -GroupScope Global -Path "OU=Groups,OU=Bydgoszcz,DC=atos,DC=net"}
  3.  
  4. #import                          #pułapka na nieuważnych
  5. $users = Import-Csv .\userzy.csv –Delimiter “;”
  6. foreach($user in $users){
  7.  
  8. $pass = ConvertTo-SecureString $user.Haslo -AsPlainText -force
  9.  
  10. New-ADUser -Name $user.id -SamAccountname $user.ID `
  11.   -Country $user.country `
  12.   -Office $user.office `
  13.   -EmailAddress $user.mail `
  14.   -GivenName $_user.imie `
  15.   -Surname $user.nazwisko `
  16.   -Department $user.department `
  17.   -DisplayName $user.displayname `
  18.   -AccountPassword $pass `
  19.   -Path "OU=Users,OU=Bydgoszcz,DC=atos,DC=net"`
  20.   -Enabled $true
  21.  
  22. #przydzielanie do grupy na bazie wartości pola Department
  23. if(($user.Department -eq 'Informatics') -or ($user.Department -eq 'IT')) {Add-ADGroupMember -Identity 'GG - Informatics' -Members $user.ID} `  
  24. if($user.Department -eq 'Sales') {Add-ADGroupMember -Identity 'GG - Sales' -Members $user.ID} `
  25. if($user.Department -eq 'Finance') {Add-ADGroupMember -Identity  'GG - Finance' -Members $user.ID}
  26.  
  27. Write-Host "Creating user: $($user.id)"
  28.  
  29. }
  30.  
  31.  
  32. <#
  33. 1. Stworz 3 grupy w AD:
  34. GG - Sales
  35. GG - Finance
  36. GG - Informatics
  37.  
  38. 2. Uzyj zalaczonego pliku CSV aby stworzyc uzytkowników. W trakcie tworzenia uzytkownika pole "Department" powinno byc sprawdzane i na jego podstawie uzytkownik bedzie dodawany do odpowiedniej grupy stworzonej w poprzednim kroku.
  39. Uzytkownicy z Sales dodawani do: "GG - Sales"
  40. Uzytkownicy z Finance dodawani do: "GG - Finance"
  41. Uzytkownicy z Informatics dodawani do: "GG - Informatics"
  42. UWAGI: Nie wolno modyfikowac pliku CSV.
  43.  
  44. 3. Jak podlinkowac GPO do nowego OU "kopiujac" linki GPO z istniejacego OU.
  45.  
  46.  
  47. https://blogs.msdn.microsoft.com/canberrapfe/2012/11/15/where-are-site-linked-group-policy-objects-stored-and-why-should-you-care/
  48. #>
  49.  ---------------------------------------------------------------------------
  50.  #Get-ADObject  -Identity "OU=OUzGPO,OU=Bydgoszcz,DC=atos,DC=net" -Properties gPlink#
  51.  #zad 3#
  52.  $src ="OU=OUzGPO,OU=Bydgoszcz,DC=atos,DC=net"
  53.  $dest="OU=NoweOU,OU=Bydgoszcz,DC=atos,DC=net"
  54.  $linked = (Get-GPInheritance -Target $src).gpolinks
  55.  foreach ($link in $linked)
  56. {
  57.     $guid = $link.GPOId
  58.     $order = $link.Order
  59.     $enabled = $link.Enabled
  60.     if ($enabled)
  61.     {
  62.         $enabled = "Yes"
  63.     }
  64.     else
  65.     {
  66.         $enabled = "No"
  67.     }
  68.     New-GPLink -Guid $guid -Target $dest -LinkEnabled $enabled
  69.     Set-GPLink -Guid $guid -Target $dest -Order $order
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement