Be sure to check out my Scripting4Crypto initiative. It’s a fun way to get into using cryptocurrencies all while getting your PowerShell needs met.
A user was attempting to retrieve all documents with a specific name within their ProjectWise datasource. The user had imported a spreadsheet listing the documents they would like to search on. The issue was that using the Get-PWDocumentsBySearch cmdlet does not allow you to search the entire datasource as there is no way to specify the ROOT folder. So trying something like the following will return an error.
# Name of file to search for. $PWFileName = 'MyIPSFile.ips' # Attempting to specify ROOT as the folder path. $Docs = Get-PWDocumentsBySearch -FolderPath ROOT -FileName $PWFileName -Verbose # Attempting to specify ROOT as the folder id of zero. $Docs = Get-PWDocumentsBySearch -FolderID 0 -FileName $PWFileName -Verbose # Attempting to return all documents by not including a folder path value. $Docs = Get-PWDocumentsBySearch -FileName $PWFileName -Verbose
Results:
The work around I came up with is to create a temporary Saved Search within PowerShell and use it to retrieve the document objects.
In the following, I am specifying the file name to be used, however for the user, they would use the value from the spreadsheet they imported. I’m also creating a variable to contain the saved search name as this will not need to change.
# Variables and values. $PWFileName = 'MyIPSFile.ips' $SavedSearch = 'TempSearch'
Next, we will use the Add-PWSavedSearch cmdlet to create a new saved search.
# Create a saved search to be used with the Get-PWDocumentsBySearch cmdlet. Add-PWSavedSearch -SearchName $SavedSearch -DocumentName $PWFileName
You can use Get-PWSavedSearches to verify the saved search was successfully created.
Get-PWSavedSearches | Where-Object Value -match $SavedSearch
Results:
Now we can used the saved search with the Get-PWDocumentsBySearch cmdlet to retrieve the document objects. You can see that there are 3 document objects returned.
$Docs = Get-PWDocumentsBySearch $SavedSearch -Verbose
Results:
Finally, we need to remove the temporary saved search from the current ProjectWise datasource. We use Remove-PWSavedSearch to accomplish this.
# Remove the temporary saved search. Remove-PWSavedSearch -SearchName $SavedSearch # Run Get-PWSavedSearches again to verify the saved search has been deleted. Get-PWSavedSearches | Where-Object Value -match $SavedSearc
Results:
Experiment with it and have fun.
Hopefully, you find this useful. Please let me know if you have any questions or comments. If you like this post, please Like button at the bottom of the page.