← script library
Automating File and Folder Permissions with PowerShell
Security & AuditingDecember 23, 2024
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:
powershell
# 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."Run it across your fleet
This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.
More in Security & Auditing
Enable the Windows Firewall with PowerShell
2026-08-17Check Windows Firewall Status with PowerShell
2026-08-17Disable SMBv1 with PowerShell
2026-08-17Enforce TLS 1.2 in the Registry with PowerShell
2026-08-17Enable RDP Network Level Authentication with PowerShell
2026-08-17Audit the Local Administrators Group with PowerShell
2026-08-17Ready when you are.
Try ServerEngine free for 7 days.