Bentley Communities
Bentley Communities
  • Site
  • User
  • Site
  • Search
  • User
ProjectWise
  • Product Communities
ProjectWise
ProjectWise PowerShell Extensions Forum PowerShell Create new ProjectWise folder from template and Excell file
    • Sign In

    • State Not Answered
    • Replies 28 replies
    • Subscribers 66 subscribers
    • Views 727 views
    • Users 0 members are here
    • powershell
    • powershellscripting
    • powerwisescripting.blog

    PowerShell Create new ProjectWise folder from template and Excell file

    JosephCyriac
    Offline JosephCyriac 28 days ago

    New-PWLogin
    
    $outfile = Get-TablesFromXLSXWorkbook -InputFileName 'C:\Users\joseph\Desktop\OutFile.xlsx '
    
    foreach($row in $outfile.rows)	
    {
        New-PWRichProjectFromTemplate -newFolderPathName $row.FolderPath -NewProjectName $row.FolderName -Template Name $row.TemplateFolder -Storage Area $row.StorageArea -verbose
    } 
    Undo-PWLogin  

    I am using the above code to create projectwise folders copying the template folder which is stored in the projectwise. But after executing one line from the Excel sheet the PowerShell quit unexpectedly. Can you please provide a solution? See below for the screenshot of the Excel file format.

    • Sign in to reply
    • Cancel

    Top Replies

    • Bill Graefe
      Offline Bill Graefe Thu, Sep 14 2023 5:12 PM in reply to JosephCyriac +1
      Did you run it in the ISE with a breakpoint then inspect the variables as you stepped through the loop? Putting $outfile | Out-GridView Before the loop with breakpoint could also help.
    • Adrian Crowfoot
      Offline Adrian Crowfoot Fri, Sep 15 2023 10:03 AM in reply to JosephCyriac +1
      JosephCyriac - I have two observations: 1. Your values have spaces. You might want to validate that your splatted hashtable values match the values in the rows. Also, make sure to remove any leading or…
    Parents
    • Brian Flaherty
      0 Offline Brian Flaherty Thu, Sep 14 2023 6:54 AM

      It appears you have some spaces within your parameter names. Should be -TemplateName and -StorageArea.  You should also add some error handling within the foreach loop. The following should work for you.

        try {
          $Splat_New = @{
            NewFolderPathName = $row.FolderPath
            NewProjectName = $row.FolderName
            TemplateName = $row.TemplateFolder
            StorageArea = $row.StorageArea
          }
          New-PWRichProjectFromTemplate @Splat_New -Verbose
        } catch {
          $_.Exception.Message
        }

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • JosephCyriac
      0 Offline JosephCyriac Thu, Sep 14 2023 11:45 AM in reply to Brian Flaherty

      New-PWLogin
      
      $outfile = Get-TablesFromXLSXWorkbook -InputFileName 'C:\Users\joseph\Desktop\OutFile.xlsx'
      
      foreach($row in $outfile.rows)
      {
          $Splat_New = @{
            NewFolderPathName = $row.FolderPath
            NewProjectName = $row.FolderName
            TemplateName = $row.TemplateFolder
            StorageArea = $row.StorageArea
          }
          New-PWRichProjectFromTemplate @Splat_New -Verbose
        } catch {
          $_.Exception.Message
        } 
      Undo-PWLogin  

      Brian Flaherty MWBSI I tried with the above Excel sheet and the code. It just created one folder in ProjectWise and then PowerShell quit. Is there any setting I need to change in ProjectWise?

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • JosephCyriac
      0 Offline JosephCyriac Thu, Sep 14 2023 2:58 PM in reply to Brian Flaherty

      it was missed in copying, see below I tried with this code, and still the same.

      # Start a ProjectWise session (replace with appropriate login command)
      New-PWLogin
      
      # Set the input Excel file path
      $inputFilePath = 'C:\Users\joseph\Desktop\OutFile.xlsx'
      
      # Import the Excel data
      try {
          $outfile = Get-TablesFromXLSXWorkbook -InputFileName $inputFilePath -ErrorAction Stop
      } catch {
          Write-Host "Error reading data from Excel file: $_"
          Exit
      }
      
      # Loop through each row in the Excel data
      foreach ($row in $outfile.rows) {
          try {
              $Splat_New = @{
                  NewFolderPathName = $row.FolderPath
                  NewProjectName = $row.FolderName
                  TemplateName = $row.TemplateFolder
                  StorageArea = $row.StorageArea
              }
      
              # Create a new ProjectWise folder from the template
              New-PWRichProjectFromTemplate @Splat_New -Verbose
      
              Write-Host "Created folder $($row.FolderName) at path $($row.FolderPath) in storage area $($row.StorageArea)"
          } catch {
              Write-Host "Error creating folder $($row.FolderName): $_.Exception.Message"
          }
      }
      
      # End the ProjectWise session
      Undo-PWLogin
      
      Write-Host "Script execution completed."
      

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • MWBSI
      0 MWBSI Thu, Sep 14 2023 3:12 PM in reply to JosephCyriac

      Too bad the try .. catch didn't work.   There's one more thing I'd like you to try.   Exchange row 1 and row 2 of the spreadsheet.  Unless someone knows a fancier way, copy row 1 to the bottom, copy row 2 row 1, copy the bottom row to row 2, then delete the bottom row.

      Delete the work area that was previously created, then re-run the script.  How far does the script get?  What gets created in ProjectWise?

      Thanks,

      Mark Weisman | Bentley Systems

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • JosephCyriac
      0 Offline JosephCyriac Thu, Sep 14 2023 3:40 PM in reply to MWBSI

      I tried that too, only the first row is working. Powershell quit after the first row. If you got some time i would love to set up a meeting via Zoom or WebEx to show exactly whats happening 

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • Bill Graefe
      0 Offline Bill Graefe Thu, Sep 14 2023 5:12 PM in reply to JosephCyriac

      Did you run it in the ISE with a breakpoint then inspect the variables as you stepped through the loop? Putting

      $outfile | Out-GridView

      Before the loop with breakpoint could also help.

      Bill

      • Cancel
      • Vote Up +1 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • Kevin van Haaren
      0 Offline Kevin van Haaren Thu, Sep 14 2023 5:33 PM in reply to JosephCyriac

      Are you getting the "Script execution completed." message?

       

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    Reply
    • Kevin van Haaren
      0 Offline Kevin van Haaren Thu, Sep 14 2023 5:33 PM in reply to JosephCyriac

      Are you getting the "Script execution completed." message?

       

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    Children
    No Data

    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