#PowerShell, #PowerWiseScripting, #ProjectWise, PWPS_DAB

HowTo: Generate Active User Account Report

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.

One of the more common administrative tasks in ProjectWise is identifying all active user accounts within a datasource. Whether you’re performing a license review, auditing user accounts, or preparing for a migration, having a clean list of active users can save a significant amount of time.

In this post, I’ll walk through a PowerShell script that generates an Excel report containing all active ProjectWise users. You will need to be logged into a ProjectWise datasource.

The Script

$pwUsers = Get-PWUsersByMatch
Write-Host "User count: $($pwUsers.Count)" -ForegroundColor Cyan
# Only want active accounts
$active = $pwUsers | Where-Object {$_.Type -NE 'Logical' -and $_.IsDisabled -eq $false}
Write-Host "Non-Logical User count: $($nonLogical.Count)" -ForegroundColor Cyan
$dtUsers = [Data.Datatable]::new("ActiveUsers")
$dtUsers.Columns.Add("UserName", [string]) | Out-Null
$dtUsers.Columns.Add("UserDesc", [string]) | Out-Null
$dtUsers.Columns.Add("Email", [string]) | Out-Null
foreach($user in $active){
Write-Host $user.UserName -ForegroundColor Cyan
if($dtUsers.Select("UserName = '$($user.UserName)'")){
Write-Host "'$($user.UserName)' already added to datatable." -ForegroundColor Magenta
continue
}
$dr = $dtUsers.NewRow()
$dr.UserName = $user.UserName
$dr.UserDesc = $user.Description
$dr.Email = $user.Email
$dtUsers.Rows.Add($dr) | Out-Null
Write-Host " - added user to datatable." -ForegroundColor Green
}
New-XLSXWorkbook -InputTables $dtUsers -OutputFileName "C:\Reports\ActiveUserReport.xlsx" -Open

Step 1 – Retrieve All Users

The script begins by retrieving every user account in the ProjectWise datasource.

$pwUsers = Get-PWUsersByMatch

The Get-PWUsersByMatch cmdlet returns all ProjectWise user objects, including logical accounts, disabled accounts, and active users.

The total number of users is displayed to provide a quick sanity check.

Step 2 – Keep Only Active Users

Next, the script removes both logical and disabled accounts.

$active = $pwUsers | Where-Object {$_.Type -NE 'Logical' -and $_.IsDisabled -eq $false}

This leaves only users who are currently active within the datasource.

Again, the script reports the remaining user count so you can easily see how many active users exist.

Step 4 – Build a DataTable

Rather than writing directly to Excel, the script creates a .NET DataTable.

$dtUsers = [Data.Datatable]::new("ActiveUsers")

Three columns are added:

  • UserName
  • UserDesc
  • Email

Using a DataTable makes it easy to manipulate data before exporting it to Excel or another format.

Step 5 – Populate the Report

The script loops through each active user and adds them to the DataTable.

foreach($user in $active)

Before adding a user, it performs a duplicate check.

$dtUsers.Select("UserName = '$($user.UserName)'")

Although duplicate usernames are uncommon, this check prevents accidentally adding the same user more than once if duplicate objects are returned.

Each user contributes:

  • Username
  • Description
  • Email Address

Progress messages are written to the console throughout execution so it’s easy to monitor larger datasources.

Step 6 – Export to Excel

Finally, the completed DataTable is exported to an Excel workbook.

New-XLSXWorkbook `
-InputTables $dtUsers `
-OutputFileName "C:\Reports\ActiveUserReport.xlsx" `
-Open

The resulting workbook contains a single worksheet listing all active ProjectWise users and automatically opens when complete.

Sample Output

UserNameUserDescEmail
jsmithJohn Smithjohn.smith@company.com
mjonesMary Jonesmary.jones@company.com
bjohnsonBob Johnsonbob.johnson@company.com

Possible Enhancements

This script provides a solid foundation for user reporting, but there are several ways it could be extended:

  • Include the user’s ProjectWise security group memberships.
  • Report the last login date.
  • Include licensing information.
  • Export to CSV in addition to Excel.
  • Sort the report alphabetically before exporting.
  • Schedule the script to run automatically and email the report to administrators.

Final Thoughts

PowerShell remains one of the most effective tools for ProjectWise administration. By combining the ProjectWise PowerShell cmdlets with .NET objects such as DataTable, it’s possible to build reports that are both fast and easy to maintain.

This Active User Report is useful for license management, user audits, migration planning, and routine administrative reviews. With only a few dozen lines of PowerShell, you can quickly generate an up-to-date inventory of every active user in your ProjectWise datasource.


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. And thank you for checking out my blog.

Leave a comment

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