Steps:
Export Permissions
Modify the permissions.csv file - Change the domain name
Import permissions
Assumptions:
User name are same in both domains
Folder structure remains the same
Exports.ps1
Get-ChildItem "S:\Folder" -Recurse | ?{ $_.PsIsContainer } | %{
$Path = $_.FullName
# Exclude inherited rights from the report
(Get-Acl $Path).Access | ?{ !$_.IsInherited } | Select-Object `
@{n='Path';e={ $Path }}, IdentityReference, AccessControlType, `
InheritanceFlags, PropagationFlags, FileSystemRights
} | Export-CSV "c:\temp\Permissions.csv"
Import.ps1
$par = Import-Csv -Path "c:\temp\Permissions.csv"
foreach ( $i in $par )
{
$path= $i.Path
$IdentityReference= $i.IdentityReference
$AccessControlType=$i.AccessControlType
$InheritanceFlags= $i.InheritanceFlags
$PropagationFlags=$i.PropagationFlags
$FileSystemRights=$i.FileSystemRights
echo $path $IdentityReference
$acl = Get-Acl c:\temp
$permission = $i.IdentityReference,$i.FileSystemRights,$i.AccessControlType
$accessRule = new-object System.Security.AccessControl.FileSystemAccessRule $permission
$acl.SetAccessRule($accessRule)
#$objACE = New-Object System.Security.AccessControl.FileSystemAccessRule ($IdentityReference, $FileSystemRights, $InheritanceFlags, $PropagationFlags, $AccessControlType)
#$objACL.AddAccessRule($objACE)
$acl | Set-Acl $path
}
Export Permissions
Modify the permissions.csv file - Change the domain name
Import permissions
Assumptions:
User name are same in both domains
Folder structure remains the same
Exports.ps1
Get-ChildItem "S:\Folder" -Recurse | ?{ $_.PsIsContainer } | %{
$Path = $_.FullName
# Exclude inherited rights from the report
(Get-Acl $Path).Access | ?{ !$_.IsInherited } | Select-Object `
@{n='Path';e={ $Path }}, IdentityReference, AccessControlType, `
InheritanceFlags, PropagationFlags, FileSystemRights
} | Export-CSV "c:\temp\Permissions.csv"
Import.ps1
$par = Import-Csv -Path "c:\temp\Permissions.csv"
foreach ( $i in $par )
{
$path= $i.Path
$IdentityReference= $i.IdentityReference
$AccessControlType=$i.AccessControlType
$InheritanceFlags= $i.InheritanceFlags
$PropagationFlags=$i.PropagationFlags
$FileSystemRights=$i.FileSystemRights
echo $path $IdentityReference
$acl = Get-Acl c:\temp
$permission = $i.IdentityReference,$i.FileSystemRights,$i.AccessControlType
$accessRule = new-object System.Security.AccessControl.FileSystemAccessRule $permission
$acl.SetAccessRule($accessRule)
#$objACE = New-Object System.Security.AccessControl.FileSystemAccessRule ($IdentityReference, $FileSystemRights, $InheritanceFlags, $PropagationFlags, $AccessControlType)
#$objACL.AddAccessRule($objACE)
$acl | Set-Acl $path
}