Forum Discussion
Nitrox
Oct 28, 2022Copper Contributor
Script to add an AD Security group to multiple User Home drive folders
Hi All I'm trying to put together a script to perform the following task: First to add an AD Security Group named "ADMigration" and assign it (Read access) to a large list of User Home Drives...
Varun_Ghildiyal
Brass Contributor
# Set the name of the AD security group to create
$GroupName = "ADMigration"
# Create the new AD security group
New-ADGroup -Name $GroupName -GroupScope Global -GroupCategory Security
# Set the list of home drive folders to modify
$HomeDriveList = @(
"\\server\share\user1",
"\\server\share\user2",
"\\server\share\user3"
)
# Loop through each home drive folder and add the AD security group to its ACL with Read access
foreach ($HomeDrive in $HomeDriveList) {
# Get the current ACL of the home drive folder
$acl = Get-Acl $HomeDrive
# Create a new Access Rule for the AD security group with Read access
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($GroupName, "ReadAndExecute", "Allow")
# Add the new Access Rule to the home drive folder's ACL
$acl.SetAccessRule($rule)
# Set the modified ACL to the home drive folder
Set-Acl $HomeDrive $acl
}
You will need to update the $GroupName and $HomeDriveList variables to match your environment. Also, make sure to run the script as an administrator and that the account you use has sufficient permissions to modify the ACLs of the home drive folders.
HALi1337
May 30, 2023Copper Contributor
Varun_Ghildiyal thanks for sharing. Working fine with few folders, but how I use it with a csv file with over 1000 fileshares?