#PowerShell, #PowerWiseScripting, #ProjectWise, PWPS_DAB

HowTo: Report on Folders w/Specific Access Control

In this post I am going to show how to return a list of folders with specific access control set. A user on the Bentley Communities site was asking for some assistance with this. He wanted to determine which folders has read / write permissions set for a specific UserList. However, this could apply to any user, group, or userlist. If you have another solution please share.

All of the ProjectWise related cmdlets are available using the PWPS_DAB module. At the time of this post, I am using version 2.1.12.0. Take a look at the help for each of the cmdlets to become familiar with their functionality, available parameters, etc.

  • Get-PWFolders
  • Get-PWFoldersByAccessMember
  • Get-PWFolderSecurity

Populate Variables

First, we will populate some variables to be used including the fullpath of a folder to report on, a member type (user, group, userlist) and a member name.

# FullPath of folder to report on. 
$FolderPath = 'BSI900 - Adelaide Tower' 
# Access control member type (User, Group, UserList). 
$MemberType = 'UserList'
# Access control member name.
$MemberName = 'CAD Users'

Get ProjectWise Folders

Next, we will get the ProjectWise folders to report on.

You might think, why not use piping instead of creating two different variables. I have tested using piping and the process takes considerably longer. Feel free to verify this for yourselves and let me know if your results are different.

# Get all folders within the folder hierarchy.
$pwFolders = Get-PWFolders -FolderPath $FolderPath
Write-Host "$($pwFolders.Count) folders returned." -ForegroundColor Green
# Get ONLY folders where access control contains the specified membername.
$Splat_Folder = @{
    InputFolder = $pwFolders
    MemberType = $MemberType
    MemberName = $MemberName
}
$pwFoldersByAccessMember = Get-PWFoldersByAccessMember @Splat_Folder
Write-Host "$($pwFoldersByAccessMember.Count) folders contain access control with member '$MemberName'." -ForegroundColor Green

Process Folders

Finally, we will process each folder and analyze the access control to determine if it contains the desired membertype and membername.

Keep in mind you could write the resulting data out to a datatable to be exported to a spreadsheet.

# Loop through each folder to determine level of access control for specified member.
foreach($f in $pwFoldersByAccessMember){
    Write-Host "$($f.FullPath)" -ForegroundColor Cyan
    $access = Get-PWFolderSecurity -InputFolder $f | 
        Where-Object name -EQ $MemberName
    Write-Host "$($access.Count) access control entries returned." -ForegroundColor Green

    <# NOTES (Possible entries)
        Work Area / Project : FPCDrw-----
        Document : FPCDrwSRWf-
    #>

    # Loop though each access control entry returned. 
    foreach($a in $access){

        <# Determine if the access control settings allow for read and/or write permission.
           We are using Regex to accomplish this.#>
        if($a.Access_Control_Settings -match '[rw]'){
            # Only display meesage if current access control entry contains either r or w.
            Write-Host " - $($a.SecurityType) has read/write access ($($a.Access_Control_Settings))" -ForegroundColor Green
        }
    }
}

Experiment with it and have fun. Hopefully, you find this useful.

Please let me know if you have any questions or comments.  If you like this post, please click the Like button at the bottom of the page.

2 thoughts on “HowTo: Report on Folders w/Specific Access Control”

  1. I have update my post on the communities site but I am still experiencing issues with the permissions. I have also found new issues where the folder permissions are showing outside of their expected ‘range’. So, I got ‘—-r-SRW–‘ from a folder / project.

    https://communities.bentley.com/products/projectwise/f/projectwise-powershell-extensions-forum/234134/export-pwprojectaccesscontrol-not-outputting-permissions-correctly

    Also, I followed your code above to see if that was the issue, but I am getting the same values returned.

    Like

    1. Hey David,

      First, thanks for visiting and following my blog. Hopefully, you find the content useful.

      As for the permissions, You may get some document level access control settings returned for the folder, which should be resolved. I will notify the developers for the module regarding this. I will follow the post of the Bentley Communities site to see if I can offer any further assistance.

      Cheers,
      Brian

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.