function Get-RandomPassword { Add-Type -AssemblyName System.Web return ([System.Web.Security.Membership]::GeneratePassword(18, 6)) } # OU Creation New-ADOrganizationalUnit -Name "COMPTABLE" -Path "DC=chromatic,DC=moe" -ProtectedFromAccidentalDeletion $true New-ADOrganizationalUnit -Name "STAGIAIRE" -Path "DC=chromatic,DC=moe" -ProtectedFromAccidentalDeletion $true New-ADOrganizationalUnit -Name "ADMINISTRATION" -Path "DC=chromatic,DC=moe" -ProtectedFromAccidentalDeletion $true New-ADOrganizationalUnit -Name "CHAUFFEUR" -Path "DC=chromatic,DC=moe" -ProtectedFromAccidentalDeletion $true # Group Creation New-ADGroup -Name "G_COMPTABLE" -Path "OU=COMPTABLE,DC=chromatic,DC=moe" -GroupScope Global -GroupCategory Security New-ADGroup -Name "G_STAGIAIRE" -Path "OU=STAGIAIRE,DC=chromatic,DC=moe" -GroupScope Global -GroupCategory Security New-ADGroup -Name "G_ADMINISTRATION" -Path "OU=ADMINISTRATION,DC=chromatic,DC=moe" -GroupScope Global -GroupCategory Security New-ADGroup -Name "G_CHAUFFEUR" -Path "OU=CHAUFFEUR,DC=chromatic,DC=moe" -GroupScope Global -GroupCategory Security # User Creation New-ADUser -Name "Emerald" -Description "Administrateur reseau" -AccountPassword $(ConvertTo-SecureString (Get-RandomPassword) -AsPlainText -Force) -ChangePasswordAtLogon $true -PasswordNeverExpires $false -Enabled $true New-ADUser -Name "Stagiaire1" -AccountPassword $(ConvertTo-SecureString (Get-RandomPassword) -AsPlainText -Force) -ChangePasswordAtLogon $true -PasswordNeverExpires $false -Enabled $true New-ADUser -Name "Comptable1" -AccountPassword $(ConvertTo-SecureString (Get-RandomPassword) -AsPlainText -Force) -ChangePasswordAtLogon $true -PasswordNeverExpires $false -Enabled $true New-ADUser -Name "Chauffeur1" -AccountPassword $(ConvertTo-SecureString (Get-RandomPassword) -AsPlainText -Force) -ChangePasswordAtLogon $true -PasswordNeverExpires $false -Enabled $true # Adding Users to Groups Add-ADGroupMember -Identity "G_ADMINISTRATION" -Members "Emerald" Add-ADGroupMember -Identity "G_STAGIAIRE" -Members "Stagiaire1" Add-ADGroupMember -Identity "G_COMPTABLE" -Members "Comptable1" Add-ADGroupMember -Identity "G_CHAUFFEUR" -Members "Chauffeur1"