Automating File and Folder Permissions with PowerShell

Welcome to our section dedicated to providing practical PowerShell scripts to enhance your IT management. Managing file and folder permissions is crucial for data security and compliance. This script automates the process of setting permissions for a specified folder, ensuring that only authorized users have the necessary access.
Here is a sample PowerShell script for managing file and folder permissions:

# Define the folder path and the users/access levels
$folderPath = "C:\SomeFolder"
$usersPermissions = @(
    @{User="Domain\User1"; Access="FullControl"},
    @{User="Domain\User2"; Access="ReadAndExecute"}
)
# Set permissions for each user
foreach ($permission in $usersPermissions) {
    $user = $permission.User
    $access = $permission.Access
    $acl = Get-Acl $folderPath
    $rule = New-Object System.Security.AccessControl.FileSystemAccessRule($user, $access, "Allow")
    $acl.SetAccessRule($rule)
    Set-Acl $folderPath $acl
    Write-Host "Granted $access access to $user for $folderPath"
}
Write-Host "File and folder permissions updated successfully."