-Recurse not working

I have a script that will output the permissions of folders. The script will run fine is pointed at a specific directory, but if the -recurse option is used there are errors. Here is the code for recurse:

#===========================================================================

Get permissions

#===========================================================================

$FolderPath = @()
$FolderPath += Get-Item -Path $Path
if ($Recurse.IsPresent)
{
$FolderPath += Get-ChildItem -Path $Path -Recurse -Force | ?{ $_.PSIsContainer }
}

$Permissions = @()
ForEach ($Folder in $FolderPath)
{
$Acl = Get-Acl -Path $Folder.FullName
ForEach ($Access in $Acl.Access)
{
$Properties = @{‘Folder Name’=$Folder.FullName;‘Identity’=$Access.IdentityReference;‘Permissions’=$Access.FileSystemRights;‘Inherited’=$Access.IsInherited;‘InheritanceFlags’=$Access.InheritanceFlags}
$Permissions += New-Object -TypeName PSObject -Property $Properties
}
}

Nick,
Welcome to the forum. :wave:t4:

Errors are an important language feature helping you knowing what’s wrong with your code. So if you get errors you should share them here completely formatted as code.

Speaking of the code formatting … When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in PowerShell.org <---- Click :point_up_2:t4: :wink: