Enumerate ACL of the current directory using power shell

928 Views Asked by At

I have been assigned with the following task. Create a foreachloop. You can use the following template:

$directory-variable-here
  foreach ($item in $directory) {
     Script block here
}

Above the foreachcondition, set a variable, $directory, to the contents of the current directory. Replace the script block placeholder with the command to enumerate the ACL of a file, using the $itemvariable in place of the file name. You'll need to use the following cmdlets: Get-ChildItem(or any alias of Get-ChildItem, such as lsor dir) Get-Acl

I need some help to solve this. Secondly what can be used to store the current directory path, I am confused.

So far I have tried the following script but it returns the current directory's content only not for subdirectories.

$dirpath= $PSScriptRoot


foreach ($item in $dirpath){
    $var = Get-ChildItem $item
    Get-Acl $var
}
1

There are 1 best solutions below

0
On

I tried a lot and after some searching, I found the solution, here is the script

$mypath= $PSScriptRoot

$var = Get-ChildItem -Recurse -Path $mypath
foreach ($item in $var){
    Get-Acl $item.FullName
    
}