-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathPermissioning.ps1
More file actions
80 lines (72 loc) · 2.76 KB
/
Permissioning.ps1
File metadata and controls
80 lines (72 loc) · 2.76 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<#
.Author
Mick Pletcher
.SYNOPSIS
Copy Permissions
.DESCRIPTION
This script will replication permissions for both files and folders using
robocopy. Change the $SourceDrive and $DestinationDrive variables to match what
you need to replicate.
#>
cls
$Errors = 0
$SourceDrive = Read-Host 'Enter source folder'
$DestinationDrive = Read-Host 'Enter destination folder'
#Match capitalization with directories
$TempDrive = Get-Item -Path $SourceDrive
$SourceDrive = $TempDrive.FullName
$TempDrive = Get-Item -Path $DestinationDrive
$DestinationDrive = $TempDrive.FullName
$SourceFolders = Get-ChildItem $SourceDrive -Recurse | ?{ $_.PSIsContainer }
$SourceFiles = Get-ChildItem $SourceDrive -Recurse -Force | where { ! $_.PSIsContainer }
$DestinationFolders = Get-ChildItem $DestinationDrive -Recurse | ?{ $_.PSIsContainer }
$DestinationFiles = Get-ChildItem $DestinationDrive -Recurse -Force | where { ! $_.PSIsContainer }
#Copy permissions for folders
$Output = robocopy $SourceDrive $DestinationDrive /ZB /E /LEV:0 /COPY:SOU /XF *.* /R:5 /W:5
#Verify Folder Permissions Match
Write-Host "Folders:"
Write-Host "========"
For ($Count=0; $Count -le $SourceFolders.Count; $Count++) {
If ($SourceFolders[$Count].FullName -ne $null) {
$SourceFolder = $SourceFolders[$Count].FullName
$DestinationFolder = $DestinationFolders[$Count].FullName
Write-Host $SourceFolder"....." -NoNewline
$SourceFolderACL = Get-Acl -Path $SourceFolder
$DestinationFolderACL = Get-Acl -Path $DestinationFolder
For ($Count1=0; $Count1 -le $SourceFolderACL.Access.Count; $Count1++) {
If ($SourceFolderACL.Access[$Count1].FileSystemRights -ne $DestinationFolderACL.Access[$Count1].FileSystemRights) {
$Errors++
}
}
If ($Errors -eq 0) {
Write-Host "Success" -ForegroundColor Yellow
} else {
Write-Host "Failed" -ForegroundColor Red
}
}
$Errors = 0
}
$Output = robocopy $SourceDrive $DestinationDrive /ZB /E /LEV:0 /COPY:SOU /XD *.* /R:5 /W:5
#Copy permissions for files
Write-Host "Files:"
Write-Host "======"
For ($Count=0; $Count -le $SourceFiles.Count; $Count++) {
If ($SourceFiles[$Count].FullName -ne $null) {
$SourceFile = $SourceFiles[$Count].FullName
$DestinationFile = $DestinationFiles[$Count].FullName
Write-Host $SourceFile"....." -NoNewline
$SourceFileACL = Get-Acl -Path $SourceFile
$DestinationFileACL = Get-Acl -Path $DestinationFile
For ($Count1=0; $Count1 -le $SourceFileACL.Access.Count; $Count1++) {
If ($SourceFileACL.Access[$Count1].FileSystemRights -ne $DestinationFileACL.Access[$Count1].FileSystemRights) {
$Errors++
}
}
If ($Errors -eq 0) {
Write-Host "Success" -ForegroundColor Yellow
} else {
Write-Host "Failed" -ForegroundColor Red
}
}
$Errors = 0
}