Bentley Communities
Bentley Communities
  • Site
  • User
  • Site
  • Search
  • User
ProjectWise
  • Product Communities
ProjectWise
ProjectWise PowerShell Extensions Forum New-PWDocumentVersion Error/Exception Handling
    • Sign In

    • State Verified Answer
    • Replies 6 replies
    • Subscribers 66 subscribers
    • Views 2164 views
    • Users 0 members are here
    • powershell
    • ProjectWise
    • Exception Handling

    New-PWDocumentVersion Error/Exception Handling

    Jim Turner
    Jim Turner over 5 years ago

    I am using New-PWDocumentVersion cmdlet as part of a script to synchronize DGN files on a server drive with the respective holdings on ProjectWise.

    To deal with problems and exceptions in my script I have the following set:

    $ErrorActionPreference = "Stop"
    $WarningPreference = "Inquire"

    The basic process involves creating a new version and uploading the PW document if the server file is more up-to-date than the PW file.  I create new versions like such and then update the file:

    Get-PWDocumentsBySearch -FolderPath $pwfolder -FileName $theFile  | New-PWDocumentVersion -VersionString $verString | Out-Null

    Get-PWDocumentsBySearch -FolderPath $pwfolder -FileName $theFile  | Update-PWDocumentFile -NewFilePathName $newfile | Out-Null 

    For an unexplained reason the New-PWDocumentVersion cmdlet is failing, with the following text written to screen:

    Error changing document '\path\xxx.dgn' to new version

    The reason for the error is not clear and I am so far unable to recreate it consistently.  Most distressingly however, because the error is not raised as a normal Powershell exception, the script blithely continues and actually overwrites the document of the previous version.

    Please can the cmdlet be updated to raise exceptions correctly?  Actually I've also noted this on other cmdlets too, including Update-PWDocumentAttributes, therefore this request can be opened up to all cmdlets.

    • Sign in to reply
    • Cancel

    Top Replies

    • Brian Flaherty
      Offline Brian Flaherty Mon, Nov 19 2018 8:24 AM +1 verified
      The New-PWDocumentVersion cmdlet has been updated to return a more informative message if/when and error occurs. Look for the update in a future release of the PWPS_DAB module.
    • Brian Flaherty
      +1 Offline Brian Flaherty Mon, Nov 19 2018 8:24 AM

      The New-PWDocumentVersion cmdlet has been updated to return a more informative message if/when and error occurs. Look for the update in a future release of the PWPS_DAB module.  

      Answer Verified By: Jim Turner 

      • Cancel
      • Vote Up +1 Vote Down
      • Sign in to reply
      • Verify Answer
      • Reject Answer
      • Cancel
    • Dean Lyon
      0 Offline Dean Lyon Wed, Nov 14 2018 8:48 AM in reply to Jim Turner

      I have the same issue with Update-PWDocumentAttributes.   It will start to fail over and over, failing to allocate memory around the 30,000th document process. However, instead of triggering the try catch, it continues until PowerShell hangs and quits.  I tried it with and without the -ErrorAction Stop.  

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • Jim Turner
      0 Jim Turner Wed, Nov 14 2018 4:08 AM

      I am managing thousands of documents.  Today, when using PowerShell to create new document versions using New-PWDocumentVersion, two documents out of a thousand failed (for no explicable reason).  The only notification is an error printed to screen:

      Error changing document 'XXX.dwg' to new version

      Because it's not raised as an exception I cannot detect the error and the next command in my script overwrites the old version and the previous data is lost. 

      How do I detect these errors?  I need an update on this please, because as it stands now I will have to stop using PowerShell.

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • Jim Turner
      0 Jim Turner Mon, Oct 29 2018 7:22 AM

      This is another example where a command has failed but not raised an exception in the expected way.  This time using the Set-PWDocumentState cmdlet.  Is there a way to capture/detect these errors and then stop the script running?

      PS C:\WINDOWS\system32> Get-PWDocumentsBySearch -FolderPath $pwfolder -FileName $theFile  | Set-PWDocumentState -State $stateShared | out-null

      Failed to change state to 'Shared' for 'XXXX.dgn'. Error: 58268

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • Jim Turner
      0 Jim Turner Wed, Oct 24 2018 4:27 AM in reply to Brian Flaherty

      I have recreated the source of the error: the $verString was invalid as it was identical to the current version. 

      However this request is rather to to ask that when errors happen they are correctly raised as exceptions so that they can be detected.  See this try-catch which fails to catch the error:

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    >

    Communities
    • Home
    • Getting Started
    • Community Central
    • Products
    • Support
    • Secure File Upload
    • Feedback
    Support and Services
    • Home
    • Product Support
    • Downloads
    • Subscription Services Portal
    Training and Learning
    • Home
    • About Bentley Institute
    • My Learning History
    • Reference Books
    Social Media
    •    LinkedIn
    •    Facebook
    •    Twitter
    •    YouTube
    •    RSS Feed
    •    Email

    © 2023 Bentley Systems, Incorporated  |  Contact Us  |  Privacy |  Terms of Use  |  Cookies