Bentley Communities
Bentley Communities
  • Site
  • User
  • Site
  • Search
  • User
ProjectWise
  • Product Communities
ProjectWise
ProjectWise PowerShell Extensions Forum Renaming bulk files in ProjectWise while referencing an Excel or .csv file
    • Sign In

    • State Suggested Answer
    • Replies 2 replies
    • Answers 1 answer
    • Subscribers 66 subscribers
    • Views 1395 views
    • Users 0 members are here

    Renaming bulk files in ProjectWise while referencing an Excel or .csv file

    Brian Springer
    Offline Brian Springer over 3 years ago

    Hello,

    We have a few hundred files in ProjectWise that need to be renamed due to client requirements. Right now, we have the these files and their path, along with the current file name and new name in respective columns, saved in both an Excel and a .csv file. Is there way to reference this excel/csv file in PowerShell to rename all these files in ProjectWise? I'm still learning PowerShell and unsure on how to get this completed right now. 

    Thank you for any possible help

    • Sign in to reply
    • Cancel
    • Ian Davidson
      0 Offline Ian Davidson Thu, Jul 23 2020 5:50 AM

      Hi Brian, 

      Yes this is something I have done before and it works well. If you look at ImportExcel on PowerShell Gallery and install it on your machine, it can read in the contents of an Excel file (Import-Excel) and create a PowerShell object for each row. Then for each object (i.e. row) you can use some of the cmdlets in the PWPS_DAB module to find the document in ProjectWise (Get-PWDocumentsBySearch) and rename it accordingly (Rename-PWDocument).

      I've included some sample code and images below to help explain.

      # Import your data from Excel
      $ImportData = Import-Excel -Path "C:\Temp\MyData.xlsx" -WorksheetName "Data"
      
      # If you want to see the data to check what has been imported
      $ImportData
      
      # Loop through each imported record
      ForEach($Record in $ImportData)
      {
          # Search for the document in PW by Folder Path and File Name
          $PWDoc = Get-PWDocumentsBySearch -FolderPath $Record.PWFolderPath -DocumentName $Record.OldFileName
         
          # Set the new name for the document
          Rename-PWDocument -InputDocument $PWDoc -DocumentNewName $Record.NewFileName
      }

      Best Regards,

      Ian

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Reject Answer
      • Cancel
    • Ian Davidson
      0 Offline Ian Davidson Thu, Jul 23 2020 7:09 AM in reply to Ian Davidson

      And just in case you are interested, you can tweak this slightly to amend custom attributes of the files also.

      # Excel Data Example
      #    --------------------------------------------------
      #   |   |       A      |     B    |   C  |      D      |
      #   |---|--------------|----------|------|-------------|
      #   | 1 | PWFolderPath | FileName | Code | Description |
      #   |---|--------------|----------|------|-------------|
      #   | 2 |              |          |      |             | 
      
      # Import your data from Excel
      $ImportData = Import-Excel -Path "C:\Temp\MyData.xlsx" -WorksheetName "Data"
      
      # If you want to see the data to check what has been imported
      $ImportData
      
      # Find what custom attributes are available to be set using first file in list
      (Get-PWDocumentsBySearch -FolderPath $ImportData[0].PWFolderPath -DocumentName $ImportData[0].FileName).GetCustomAttributes()
      
      # Loop through each imported record
      ForEach($Record in $ImportData)
      {
          # Search for the document in PW by Folder Path and File Name
          $PWDoc = Get-PWDocumentsBySearch -FolderPath $Record.PWFolderPath -DocumentName $Record.FileName
         
          # Set the new attributes for the document
          Update-PWDocumentAttributes -InputDocuments $PWDoc -Attributes @{PW_CODE = $Record.Code; PW_DESCRIPTION = $Record.Description }
      }
      

      • 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