Home > front end >  I want to make a report in powershell to export to csv of users and groups access
I want to make a report in powershell to export to csv of users and groups access

Time:10-07

I want to make a report in Powershell of users and groups that access to determine folder only to root folder no subfolders.
I don't know programming in PowerShell, and I copied the code from a website, but the report give me each folder and subfolders

$FolderPath = dir -Directory -Path "\\fs1\Shared" -Recurse -Force
$Report = @()
Foreach ($Folder in $FolderPath) {
    $Acl = Get-Acl -Path $Folder.FullName
    foreach ($Access in $acl.Access)
    {
        $Properties = [ordered]@{'FolderName'=$Folder.FullName;'AD Group or User'=$Access.IdentityReference;'Permissions'=$Access.FileSystemRights;'Inherited'=$Access.IsInherited}
        $Report  = New-Object -TypeName PSObject -Property $Properties
    }
}
$Report | Export-Csv -path "C:\data\FolderPermissions.csv"

CodePudding user response:

Remove the -Recurse flag from the Get-ChildItem call - otherwise it'll recurse down through the folder hierarchy :)

  • Related