Wednesday 26 February 2014

Export and Import NTFS permission with Powershell from one domain to another

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
        }





Friday 21 February 2014

Release Mapped Files from Memory

User RAMMap to identify the leaked memory if a mapped file is cause of the problem then use following to fix this immediately:

1. Highlist the Mapped file
2. From Menu select 'Empty' > 'Empty Working Sets'
3. All the locked memory should be released, press F5 to refresh see the Mapped file total moved to Standby.
4. Again select 'Empty' from Menu bar > Empty Standby
5. F5 to refresh