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
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
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 } }