Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Where-Object : A positional parameter cannot be found that accepts argument 'Foreach'

$
0
0

PS U:\> PS U:\> $OutFile = "C:\temp\Documents\Permissions1.csv" # Insert folder path where you want to save your file and its name
$Header = "Folder Path,IdentityReference,AccessControlType,IsInherited,InheritanceFlags,PropagationFlags"
$FileExist = Test-Path $OutFile 
If ($FileExist -eq $True) {Del $OutFile} 
Add-Content -Value $Header -Path $OutFile 
$RootPath = "\\server\sharename" # Insert your share path
Get-ChildItem $RootPath | where {$_.psiscontainer} | where { $_ | Get-Acl | select -ExpandProperty Access | where {$_.IdentityReference -contains $aclfullname}}
$Folders = dir $RootPath -recurse | where {$_.psiscontainer -eq $true} Foreach $Folder in $Folders{
    $ACLs = get-acl $Folder.fullname | ForEach-Object { $_.Access  }
    Foreach ($ACL in $ACLs){
    $OutInfo = $Folder.Fullname + "," + $ACL.IdentityReference  + "," + $ACL.AccessControlType + "," + $ACL.IsInherited + "," + $ACL.InheritanceFlags + ","+ $ACL.PropagationFlags
    Add-Content -Value $OutInfo -Path $OutFile 
    }}

Thanks in advance.


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>