You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Examples.md 3.4 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. ### Get-NTFSAccess
  2. Returns a list of all access control entries found on the given object(s).
  3. #Get permissions from all files or folders in the current folder
  4. dir | Get-NTFSAccess
  5. #to read the permissions of a specific file
  6. Get-NTFSAccess -Path C:\Windows
  7. #### Get permissions from all files or folders in the current folder
  8. dir | Get-NTFSAccess
  9. #### To read and also remove only the explicitly assigned ones
  10. dir | Get-NTFSAccess -ExcludeInherited | Remove-NTFSAccess
  11. The pipeline support can also be used to backup and restore permissions of one or many items:
  12. PowerShell
  13. #### To backup permissions just pipe what Get-NTFSAccess returns to Export-Csv
  14. dir | Get-NTFSAccess -ExcludeInherited | Export-Csv permissions.csv
  15. #### To retore the permissions pipe the imported data to Get-NTFSAccess
  16. As the imported data also contains the path you do not need to specify the item
  17. Import-Csv .\permissions.csv | Get-NTFSAccess
  18. All cmdlets can handle SIDs and also SamAccountNames. The output contains always both unless a SID is not resolvable.
  19. The types.ps1xml file is extending the common objects with some useful information and the format.ps1xml file formats all the output in almost the same way like the Get-ChildItem output.
  20. By implementing the [Process Privilege http://processprivileges.codeplex.com/] project the cmdlets can activate the required privileges for setting the ownership for example.
  21. # Add-NTFSAccess
  22. Adds a specific ace to the current object. This can be done in just one line:
  23. Get-Item .\VMWare | Add-NTFSAccess -Account Contoso\JohnD -AccessRights FullControl
  24. # Get-NTFSAccess
  25. Gives you a list of all permissions . normally you are interested not in the inherited permissions so the switch ExcludeInherited can be useful
  26. Get-Item F:\backup | Get-NTFSAccess –ExcludeInherited
  27. ## Filtering works with Where-Object
  28. Get-Item F:\backup | Get-NTFSAccess | Where-Object { $_.ID -like "*users*" }
  29. # Get-NTFS Orphaned Access
  30. Lists all permissions that can no longer be resolved. This normally happens if the account is no longer available so the permissions show up as a SID and not as an account name.
  31. To remove all non-resolvable or orphaned permissions you can use the following line. But be very careful with that as maybe the account is not resolvable due to a network problem.
  32. dir -Recurse | Get-NTFSOrphanedAccess | Remove-NTFSAccess
  33. # Remove- NTFSAccess
  34. Removes the permission for a certain account. As the pipeline is supported it takes also
  35. ACEs coming from Get-NTFSAccess or Get-NTFSOrphanedAccess
  36. # Get-NTFSEffectiveAccess
  37. Shows the permissions an account actually has on a file or folder. If no parameter is specified it shows the effective permissions for the current user. However you can supply a user by using the SID or account name
  38. PowerShell
  39. Get-Item F:\backup | Get-NTFSEffectiveAccess -Account S-1-5-32-545
  40. # Get-NTFSInheritance
  41. Shows if inheritance is blocked
  42. # Enable-NTFSInheritance
  43. It can be a problem if certain files or folders on a volume have inheritance disabled. Making sure that inheritance is enabled can be done using this cmdlets:
  44. Get-Item .\Data -Recurse | Enable-NTFSAccessInheritance
  45. # Disable-NTFSInheritance
  46. See Enable-NTFSInheritance
  47. # Get-NTFSOwner
  48. Shows the owner of a file or folder
  49. dir -Recurse | Get-NTFSOwner
  50. # Set-NTFSOwner
  51. Sets the owner to a specific account like:
  52. Get-Item .\Data | Set-NTFSOwner -Account builtin\administrators