-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFixPermissions.ps1
55 lines (51 loc) · 2.49 KB
/
FixPermissions.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# ********************************************************************************
#
# Script Name: FixPermissions.ps1
# Version: 1.0
# Author: Sheridan Wendt
# Date: 9/26/2017
# Applies to: User Folders
#
# Description: This script will copy the permissions of a template folder
# ($Template) then assign those permissions to a list of folders inside of a root
# folder. It will also add an access rule ($AR) to the copied permissions, which
# is useful to grant "Modify" access to the folder for a user that has the same
# name as the $SubFolder.name (works only when the folder name is the same as the
# username, such as a Home Drive.)
#
# ********************************************************************************
$Greeting = @"
########################################################################
# #
# Welcome to the Fix Permissions Script! #
# -------------------------------------- #
# #
# Description: This script will copy the permissions of a template #
# folder ($Template) then assign those permissions to a list of #
# folders inside of a root folder. It will also add an access rule #
# ($AR) to the copied permissions, which is useful to grant "Modify" #
# access to the folder for a user that has the same #
# name as the $SubFolder.name (works only when the folder name is the #
# same as the username, such as a Home Drive.) #
# #
########################################################################
Insert address for Template folder with no backslash on the end.
Example: \\FileServer\F$\Template
"@
$Greeting
Function Set-Permissions{
$Template = Read-Host "Template Address"
$TemplateACL = Get-Item "$Template"
$RootFolder = Read-Host "Root Folder"
$RootDirectory = Get-ChildItem "$RootFolder" -Directory
foreach ($SubFolder in $RootDirectory) {
$Path = $SubFolder.FullName
$ACL = ($TemplateACL).GetAccessControl('Access')
$Username = $SubFolder.Name
$AR = New-Object System.Security.AccessControl.FileSystemAccessRule($Username, 'Modify', 'ContainerInherit,ObjectInherit', 'None', 'Allow')
$ACL.AddAccessRule($AR)
Set-Acl -path $Path -ACLObject $ACL
}
}
Set-Permissions
Write-Host "Done"