Skip to content

Instantly share code, notes, and snippets.

@HiteaFR
Created September 26, 2023 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HiteaFR/36cac8778751d1d857e0fa780f56dc1d to your computer and use it in GitHub Desktop.
Save HiteaFR/36cac8778751d1d857e0fa780f56dc1d to your computer and use it in GitHub Desktop.
Créer des dossiers personnels dans un domaine avec Powershell
$OU_path = "OU_PATH"
$Base_Folder = "RUN_FOLDER"
$users = get-aduser -SearchBase $OU_path -filter * -Properties UserPrincipalName | % { $_.UserPrincipalName.Split('@')[0] }
$users | ForEach {
$folder = join-path -path $Base_Folder -childpath $_
If (!(Test-Path -Path $folder )) {
New-Item -Path $folder -ItemType Directory
$acl = Get-Acl $folder
$acl.SetAccessRuleProtection($true, $true)
$AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($_, "FullControl", "ContainerInherit,ObjectInherit", "None", "Allow")
$acl.SetAccessRule($AccessRule)
$acl | Set-Acl $folder
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment