In this post, I'll show a script to refresh the ProjectWise Explorer Client from PowerShell. Many thanks to ChatGPT for some assistance. This script will select the "ProjectWise Datasources" item within the Datasource Listing and refresh. Can be used when enabling/disabling ProjectWise Datasources. I am not going to break down the code in this one, simply provide it.
[NOTE] Updated to deal with when a document or folder is selected in the Document List control. Will now navigate back to the Datasource Listing and refresh.
Script Contents
The following is the entire script content.
Add-Type @"
using System;
using System.Runtime.InteropServices;
using System.Text;
public class Win32 {
public delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool EnumWindows(EnumWindowsProc lpEnumFunc, IntPtr lParam);
[DllImport("user32.dll", SetLastError = true)]
public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll", SetLastError = true)]
public static extern int GetWindowTextLength(IntPtr hWnd);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool SetForegroundWindow(IntPtr hWnd);
public static string GetWindowTitle(IntPtr hWnd) {
int length = GetWindowTextLength(hWnd);
if (length == 0) return null;
StringBuilder sb = new StringBuilder(length + 1);
GetWindowText(hWnd, sb, sb.Capacity);
return sb.ToString();
}
}
"@
# Function to find the window by its partial title
function Get-WindowHandleByPartialTitle {
param (
[string]$PartialTitle
)
$foundHwnd = [IntPtr]::Zero
$callback = {
param ($hWnd, $lParam)
if ([Win32]::GetWindowTitle($hWnd) -like "*$PartialTitle*") {
$script:foundHwnd = $hWnd
return $false
}
return $true
}
[Win32]::EnumWindows($callback, [IntPtr]::Zero) | Out-Null
return $script:foundHwnd
}
# Select the top item and refresh
function Select-TopItemAndRefresh {
param (
[string]$WindowName
)
$mainWindow = Get-WindowHandleByPartialTitle -PartialTitle $WindowName
if ($mainWindow -eq [IntPtr]::Zero) {
Write-Warning "Window '$WindowName' not found."
return
}
# Bring the window to the foreground
[Win32]::SetForegroundWindow($mainWindow) | Out-Null
Start-Sleep -Milliseconds 500
# Send keystrokes to select the top item and refresh
# Simulates a [SHIFT] [TAB] to get you back to the Datasource Listing control.
[System.Windows.Forms.SendKeys]::SendWait("+{TAB}")
# Go to the top and refresh.
[System.Windows.Forms.SendKeys]::SendWait("{HOME}{F5}")
Write-Output "Top item selected and refresh triggered."
}
# Example usage
$WindowName = "ProjectWise Explorer"
Select-TopItemAndRefresh -WindowName $WindowName
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.

Brian,
Thanks again for this fix!
Great Job!
I did notice if a user has a file or folder selected on the right side in PWE, it will go to the top of that list and not the datasource listing?
LikeLike
I did not test for that. I’ll see what I can do to resolve.
LikeLike
See the Bentley Communities site. I have posted an update with a solution.
LikeLike