#PowerShell, #PowerWiseScripting, #ProjectWise, PWPS_DAB

How To: Get a List of UserList and Groups a User is a Member Of

Be sure to check out my Scripting4Crypto initiative. It’s a fun way to get into using cryptocurrencies all while getting your PowerShell needs met.

I’ve got another quick one for you today.  Had a request to generate a list of all userlists and groups that each user within a ProjectWise datasource is a member of.  In this example, I am simply outputting the information to the console, but there is no reason you couldn’t export to a CSV file or Excel spreadsheet.

We will be using the following cmdlets to accomplish this task. All of the cmdlets are available using the PWPS_DAB module. Take a look at the help for each of the cmdlets to become familiar with their functionality, available parameters, etc.

  • Get-PWUsersByMatch
  • Get-PWGroupsByUser
  • Get-PWUserListsByMember

First thing we will do is create a list of the ProjectWise User accounts that we want to report on. We could work with ProjectWise User Objects, however, I am only interested in the user name. To create this list we will use the Get-PWUsersByMatch cmdlet and use a Select-Object to only return the user names.

For this example I am retrieving all ProjectWise users within my datasource. This could easily be filtered to get a subset of users by using Where-Object.

# Get a list of all user names to verify.
$Users = Get-PWUsersByMatch | Select-Object Name

The following is the list of user names returned.

AllUsers

Now that we have the list of users, we can loop through the list and get any groups or userlists that each user is a member of. We will use the Get-PWGroupsByUser and Get-PWUserListsByMember cmdlets. For the Get-PWUserListsByMember we need to ensure y the MemberType is set to user.

# Loop through list of names, and get the groups and userlists they are a member of.
foreach ($User in $Users) {
    Write-Host "$($User.Name)"

    # Get all Groups that user is a member of.
    $tempGroups = Get-PWGroupsByUser -UserName $User.Name 
    # Get all UserLists that user is a member of.
    $tempUserLists = Get-PWUserListsByMember -MemberName $User.Name -MemberType user

    # Output the group membership information to the console.
    foreach ($tempGroup in $tempGroups.Keys) {
        Write-Host "-- Group: $($tempGroups[$tempGroup])."
    }

    # Output the userlist membership information to the console.
    foreach ($tempUserList in $tempUserLists.Keys) {
        Write-Host "-- UserList: $($tempUserLists[$tempUserList])"
    }
}

The following shows the resulting output for this process. Again, you could easily output this information to a CSV file or Excel spreadsheet.

Membership

Experiment with it and have fun.

Hopefully, you find this useful. Please let me know if you have any questions or comments.

Leave a comment

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