In this post, we will be looking at how to scan a compiled configuration file for MicroStation, OpenRoads Designer, or any other MicroStation based product for invalid path values. This is accomplished by finding any path value containing “pw://”. The “pw://” indicates that the ProjectWise folder or document object could not be found. We are going to use the -debug option to generate a file containing all of configuration data. You could do something similar with the compiled configuration file generated in the workspace folder within the ProjectWise local working directory.
There are many other ways to accomplish this task. Feel free to share what you have developed.
All of the ProjectWise related cmdlets are available using the PWPS_DAB module. At the time of this post, I am using version 23.4.1. Take a look at the help for each of the cmdlets to become familiar with their functionality, available parameters, etc.
- New-XLSXWorkbook
ProjectWise / MicroStation 2023
We will open a MicroStation 2023 design file from within ProjectWise which has a Workspace applied to the folder.
Setup Program Association
From within ProjectWise- Click Tools > Associations > Programs
- The Program Associations dialog will display.
- Switch the “Select an association view:” to “User associations“
- Select the appropriate MicroStation application
- Right mouse-click on Open
- Select Add Association
- Select the desired program from the list.
- In our case it will be MicroStation 2023.
- Click OK
- Double-click on the “Command Line Arguments:”
- Enter -debug
- Click OK to accept
- Click OK to close the Program Associations dialog
Open a design file using the new MicroStation 2023 program association.
- Right mouse-click on the desired MicroStation 2023 design file
- Click Ok
- A MicroStation – Text Window displays
- Notepad opens displaying the content of the msdebug.txt file.
The command window and notepad will open displaying the content of the msdebug.txt file. I like to save the file to the c:\Temp or other folder for ease of access and rename to add the application to the file name.
From within Notepad
- Click File > Save As
- Navigate to the “C:\PowerShell\MicroStation Variable Reporting” folder
- Enter PW_MS2023_msdebug.txt
- Click Save
Process Debug File
Now we can process the debug file within PowerShell. We will only process the section of the debug file between lines beginning with “Processing macro file” and “End of macro file”.
From within PowerShell we will need to populate the values of a few variables.
$Path = "C:\PowerShell\MicroStation Variable Reporting" $FileName = "PW_MS2023_msdebug.txt" # Configuration file to scan for unique variables. $ConfigurationFile = "$Path\$FileName" # Path and name of report. $OutputFileName = "$Path\$($FileName.Split('.')[0])_Variables_$(Get-Date -Format yyyyMMdd_hhmm).xlsx"
We will read the content of the configuration/debug file. If nothing read, the script will throw an error.
# Opening of the try/catch block. try{ if( -not ( $content = Get-Content $ConfigurationFile )){ throw "Failed to get file content." } else { Write-Host "$($content.Count) lines read from file '$ConfigurationFile'." -ForegroundColor Cyan }
Create a datatable to populate with the invalid path data. When we find an invalid path, we will capture the line number, level, variable name, operand, and the value.
# Datatable to store the invalid path data in. $dtVariableUsage = [Data.Datatable]::new("VariableUsage") $dtVariableUsage.Columns.AddRange(@( 'Line #' 'Level' 'VariableName' 'Operand' 'Value' ))
Loop through all of the content to capture any invalid path values.
[int]$lineNumber = 0 foreach($line in $content){ $lineNumber++ # Skip if line is empty. # Skip "Processing macro file" line. # Stop processing when "End of macro file" line is found. if([string]::IsNullOrEmpty($line)){ continue } elseif( $line.StartsWith("Processing macro file")){ continue } elseif ($line.StartsWith("End of macro file")){ throw "End of file." } # Split the string only at the first colon. $split = $line -split ":", 2 $Level = $split[0].Trim().TrimStart('(').TrimEnd(')') $Value = $split[1].Trim() $Operand = [string]::Empty # Parse value to get variable name, variable operator and variable value. if($value.Contains('=')){ $Operand = "=" $split_Value = $Value -split "=" } elseif ($Value.Contains('>')){ $Operand = ">" $split_Value = $Value -split ">" } elseif ($value.Contains('<')){ $Operand = "<" $split_Value = $Value -split "<" } elseif ($value.Contains(':')){ $Operand = ":" $split_Value = $Value -split ":", 2 } # If the value contains "pw://" add to datatable. Otherwise, continue to next line. if( -not ($split_Value[1].Contains("pw://"))){ continue } # Add row to datatable. $dtVariableUsage.Rows.Add($lineNumber, $Level, $split_Value[0].Trim(), $Operand, $split_Value[1].Trim()) | Out-Null } # end foreach($line in $content)... } catch { Write-Warning -Message $_ }
Finally, if any invalid paths were found, we will generate a report.
if($dtVariableUsage.Rows.Count -gt 0){ New-XLSXWorkbook -InputTables $dtVariableUsage -OutputFileName $OutputFileName -Open }
The following shows an example output. I have obfuscated the values.
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.
