Bentley Communities
Bentley Communities
  • Site
  • User
  • Site
  • Search
  • User
ProjectWise
  • Product Communities
ProjectWise
ProjectWise PowerShell Extensions Forum Multi-threading or Using Jobs
    • Sign In

    • State Not Answered
    • Replies 10 replies
    • Subscribers 66 subscribers
    • Views 340 views
    • Users 0 members are here
    • powershell
    • ProjectWise
    • pwps_dab

    Multi-threading or Using Jobs

    Brian Flaherty
    Offline Brian Flaherty 1 month ago

    Hello All,

    I have a script which loops through multiple datasources to gather data for each, populate a datatable and export to an Excel file. Simple enough.

    My question is, has anyone tried to using either some type of multi-threading or jobs, to simultaneously process multiple datasources?  Hope this makes sense.

    I am trying to cut the amount of time to run the script and gather the data. Thanks in advance.

    Cheers,

    Brian

    • Sign in to reply
    • Cancel

    Top Replies

    • Robert McMillan
      Offline Robert McMillan Wed, Oct 18 2023 8:18 PM +2
      You could also look at PowerShell Workflows with the -parallel & -throttlelimit switches. Here's something I did with running multiple scanrefs.exe instances in parallel. Workflow Scan-ReferencesMultithreaded…
    • Robert McMillan
      Offline Robert McMillan Thu, Oct 19 2023 6:33 PM in reply to Kevin van Haaren +2
      I'm using PowerShell 5.1 as well and I think the -parallel switch is only available within the context of a Workflow function. This wasn't specifically using PWPS_DAB cmdlets and I think with Scope issues…
    Parents
    • Robert McMillan
      0 Offline Robert McMillan Wed, Oct 18 2023 8:18 PM

      You could also look at PowerShell Workflows with the -parallel & -throttlelimit switches. Here's something I did with running multiple scanrefs.exe instances in parallel.

      Workflow Scan-ReferencesMultithreaded {
          Param ( 
              [Parameter (Mandatory)]
              [String] $Datasource,
      
              [Parameter (Mandatory)]
              [String] $UserName,
      
              [Parameter (Mandatory)]
              [String] $Password,
      
              [Parameter (Mandatory)]
              [String[]] $DocumentGUIDs
          )
          $Threads = 4
          $FilePath = 'C:\Program Files (x86)\Bentley\ProjectWise\bin\scanrefs.exe'
      
          foreach -parallel -throttlelimit $Threads ($DocumentGUID in $DocumentGUIDs) {
              $Params = @{
                  FilePath     = 'C:\Program Files (x86)\Bentley\ProjectWise\bin\scanrefs.exe'
                  ArgumentList = @('-d', $Datasource,
                                   '-u', $UserName,
                                   '-p',  $Password,
                                   '-mode', 'references',
                                   '-masters', "{$DocumentGUID)}",
                                   '-priority', "`"r:FolderPath`"",
                                   '-order', 'priority'
                                  )
                  Wait         = $true
                  WindowStyle  = [System.Diagnostics.ProcessWindowStyle]::Hidden
              }
              $Process = Start-Process @Params
          }
      }

      • Cancel
      • Vote Up +2 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • Kevin van Haaren
      0 Online Kevin van Haaren Thu, Oct 19 2023 12:17 PM in reply to Robert McMillan

      Ohhh, I like that, but isn't ForEach -Parallel a PowerShell 7 feature? I don't see it when i do Help Foreach-Object in my PowerShell 5.1. This script doesn't require it, but do you have PWPS_DAB working with PowerShell 7? I haven't tried in a while but it didn't work for me when I last tried a few years agao.

       

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    Reply
    • Kevin van Haaren
      0 Online Kevin van Haaren Thu, Oct 19 2023 12:17 PM in reply to Robert McMillan

      Ohhh, I like that, but isn't ForEach -Parallel a PowerShell 7 feature? I don't see it when i do Help Foreach-Object in my PowerShell 5.1. This script doesn't require it, but do you have PWPS_DAB working with PowerShell 7? I haven't tried in a while but it didn't work for me when I last tried a few years agao.

       

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    Children
    • Robert McMillan
      0 Offline Robert McMillan Thu, Oct 19 2023 6:33 PM in reply to Kevin van Haaren

      I'm using PowerShell 5.1 as well and I think the -parallel switch is only available within the context of a Workflow function. This wasn't specifically using PWPS_DAB cmdlets and I think with Scope issues you might need to handle datasource login within the foreach loop as well so may have limited use depending on the task at hand.

      • Cancel
      • Vote Up +2 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