N
N
Nizitka2019-07-31 09:26:45
PowerShell
Nizitka, 2019-07-31 09:26:45

How does assignment work in powershell?

Why when executing:

$crdir="C:\temp"
$acl = Get-Acl $crdir
$newacl=$acl
$newacl.SetAccessRuleProtection($True, $false)
$acl |ft -Wrap
$newacl |ft -Wrap

output of $acl and $newacl variables same?
the action is performed only with $newacl, or I don't understand something.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nizitka, 2019-08-01
@Nizitka

Answered elsewhere.
For those interested, this is a reference data type.

E
Eugene, 2019-07-31
@BeatHazard

The .SetAccessRuleProtection method performs two actions, the first - blocks inheritance of permissions from the parent / enables inheritance for the object, the second - leaves inherited permissions as explicitly set permissions / removes inherited permissions and leaves only those that were explicitly set.
Thus, most likely you simply do not have any inherited permissions for the folder "C:\temp" If you for example create a subfolder in "C:\temp", give the folder "C:\temp" permissions and enable inheritance, then after execution $newacl.SetAccessRuleProtection($True, $false) when applied to a folder inside "C:\temp" the output between $acl and $newacl will be different because permission inheritance will be removed.
You can read more herehttps://windowsnotes.ru/powershell-2/upravlenie-ac...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question