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
}
Hi, thank You for script. Export works perfect, but when I try to import permissions from CSV Import.ps1 imports only las user/permission from CSV file :(
ReplyDeletechange line:
ReplyDelete$acl = Get-Acl c:\temp
$permission = $i.IdentityReference,$i.FileSystemRights,$i.AccessControlType
to become:
$acl = Get-Acl $path
$permission = $IdentityReference, $FileSystemRights, $InheritanceFlags, $PropagationFlags, $AccessControlType
hello,
Deletewhen run import this message displays:
At line:14 char:37
+ $permission = $.Identity, $.FileSystemRights, $.AccessC ...
+ ~
Missing argument in parameter list.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingArgument
can you help me please?
best regards
Thanks Kevin :)
ReplyDeleteHow can you import the inheritance flags?
ReplyDeleteI have removed the comment in the 2 lines of the import file but now receiving error.
"You cannot call a method on a null-valued expression"
Thank you
I got the same error, when i changed the paths in permissions.csv, found out that the Problem was Excel, Changed path with Notepad++, everything worked.
ReplyDeleteWHAT IS THE DIFFRENCE FAT32 & NTFS ?
ReplyDeletentfs permissions analyzer
You don't belong here.
DeleteIs there a way to extract group permissions as well as user permissions? I have the same group names in both domains and want to migrate the group permissions too.
ReplyDeleteSeth - it already does group permissions for me without changes.
ReplyDeleteImport code does not work, unexpected error code number 1
ReplyDelete