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.
In this post, we’ll walk through a PowerShell example that prompts a user to select a ProjectWise folder and then programmatically adds a custom comment to that folder’s audit trail using the ProjectWise API.
Why Add Audit Trail Entries Programmatically?
There are several scenarios where this approach is valuable:
- Recording bulk administrative changes
- Providing traceability for custom tools or scripts
- Maintaining compliance and accountability
By explicitly writing to the audit trail, you ensure that automated actions are just as transparent as those performed manually in ProjectWise Explorer.
The PowerShell Example
Below is the complete script used to add an audit trail comment to a selected folder.
# Select ProjectWise folder to add comment to.
$pwFolder = Show-PWFolderBrowserDialog
# The folder guid associated with the selected folder.
$guid = $pwFolder.ProjectGUIDString
# Empty guid for parameter.
$guidEmpty = [guid]::Empty
# Comment to be added to the audit trail for the selected folder.
$Comment = "Removed Workflow via PowerShell."
if([pwwrapper]::aaApi_CreateAuditTrailRecordByGUID([PWWrapper+AuditTrailTypes]::AADMSAT_TYPE_VAULT, ([ref] $guid), 2, $Comment , 0, 0, [string]::Empty, ([ref] $guidEmpty))){
Write-Host "Successfully added comment to folder audit trail." -ForegroundColor Cyan
} else {
Write-Warning -Message "$([pwwrapper]::aaApi_GetMessageByErrorId([pwwrapper]::aaApi_GetLastErrorId()))"
}
Script Breakdown
Let’s take a closer look at what’s happening.
1. Folder Selection
This displays the standard ProjectWise folder browser dialog and returns the selected folder object.
2. Extracting the Folder GUID
The audit trail API requires a GUID reference, which uniquely identifies the folder in ProjectWise.
3. Preparing the Audit Trail Comment
This is the text that will appear in the folder’s audit trail. You can dynamically generate this based on your script logic if needed.
4. Writing to the Audit Trail
Key points:
- AADMSAT_TYPE_VAULT specifies a vault-level audit trail entry.
- The folder GUID is passed by reference.
- The comment is written exactly as provided.
- The empty GUID reference is required by the API even when unused.
If the call succeeds, the script confirms success (returns a true or false). If it fails, the ProjectWise error message is retrieved and displayed.
Result in ProjectWise
Once executed successfully, the comment will appear in the folder’s Audit Trail tab in ProjectWise Explorer—clearly indicating that the action was performed via PowerShell.
This is especially useful when running scripts as part of:
- Scheduled tasks
- Admin-only utilities
- Bulk cleanup or migration efforts
Final Thoughts
Automating audit trail entries is a small addition that provides big value. It improves traceability, reduces confusion, and makes your PowerShell-based ProjectWise tools more professional and supportable.
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.
