PoshCode Archive  Artifact [2d602529fa]

Artifact 2d602529fa83307d4b52083b221332b1c5ae1d419109d292a20aa905357cb05f:

  • File Folder-inheritance.ps1 — part of check-in [9e6f5c00bf] at 2018-06-10 14:02:00 on branch trunk — Change the inheritance from parent with PowerShell (user: Vern Anderson size: 1356)

# encoding: ascii
# api: powershell
# title: Folder inheritance
# description: Change the inheritance from parent with PowerShell
# version: 0.1
# type: script
# author: Vern Anderson
# license: CC0
# x-poshcode-id: 5818
# x-archived: 2016-05-04T11:53:55
# x-published: 2016-04-08T18:03:00
#
#
# setup the test folders
   md c:\grandfather\father\son
   md c:\grandmother\mother\daughter

# By default the folders will inherit ACLs from the C: drive
# To toggle it or change it to the desired setting

# Will force the inheritance from parent
      $inheritance = get-acl c:\grandmother
      $inheritance.SetAccessRuleProtection($false,$false)
      set-acl c:\grandmother -aclobject $inheritance
#Display the new state
      (Get-Acl c:\grandmother).AreAccessRulesProtected

#############################################################
# Second script to go the other way
#############################################################

# Will remove the inheritance from parent

      $inheritance = get-acl c:\grandfather
      $inheritance.SetAccessRuleProtection($true,$true)
      set-acl c:\grandfather -aclobject $inheritance
#Display the new state
      (Get-Acl c:\grandfather).AreAccessRulesProtected

# As you can see changing the ($false,$false) to ($true,$true) is the only difference in the 2 scripts