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.I was recently working on a project where I needed to export a large number of folders and documents from ProjectWise to a local folder. The folders were broken up into about 20 different folder hierarchies, each containing many projects. After exporting all of the files I needed to validate the number of files exported.
Document Count from ProjectWiseFirst, I would get a document count from ProjectWise. I will pipe the results of the Get-PWDocumentsBySearch cmdlet to the Measure-Object cmdlet. I will then pipe those results to the Select-Object to only get the information needed. The result is the number of documents contained in the provided folder.
# Get all documents in folder hierarchy. Get-PWDocumentsBySearch -FolderPath 'Project' | Measure-Object | Select-Object CountThere were 13,844 documents returned for this folder hierarchy.
File Count from Windows FolderNext, I would get a file count from the corresponding Windows folder. For this I will use the Get-ChildItem cmdlet and filter the results to only include files. I then pipe the results to the Measure-Object cmdlet. The result is the number of files contained in the Windows folder hierarchy. The Get-ChildItem will return both folders and files. We filtered on files. The following shows the returned mode types.
- Folder: ‘d—–‘
- Files: ‘-a—-‘
<# Get file count from Windows folder. Use the -Recurse switch parameter with the Get-ChildItem cmdlet to return files from the entire folder hierarchy. #> Get-ChildItem -Path 'C:\ProjectExport' -Recurse | Where-Object Mode -EQ '-a----' | Measure-Object | Select-Object CountThere were 11,492 documents returned for this folder hierarchy.
ObservationObviously, there is a discrepancy between the two counts. 2,352 to be exact. I will need to determine which documents were not exported and why. That is a topic for another post.
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 click the Like button at the bottom of the page.