#PowerShell, #PowerWiseScripting, #ProjectWise, PWPS_DAB

How To: Export ProjectWise Documents to a Zip File Using PowerShell

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.

With the release of PWPS_DAB module version 1.6.1.0, we now have the ability to export ProjectWise documents out to a zip file on a local drive. This is accomplished using the Export-PWDocumentFilesToZip PowerShell cmdlet.

It is a fairly straight forward process. However, first things first. Take a look at the help for the Export-PWDocumentFilesToZip cmdlet to familiarize yourself with the available parameters, etc.

Get-Help Export-PWDocumentFilesToZip -Full

This cmdlet has a few required parameters that we will need to deal with.

  • InputDocuments
  • OutputFileName

There are two optional parameters we will also take a look at.

  • FolderPrefixToRemove
  • UseDMSFolders

Now, we will create and populate a few variables with the ProjectWise Folder Path which contains the documents we will export and the path and name of the zip file to export to. Keep in mind you could use other methods to select the ProjectWise documents, such as a saved search.

# Path to ProjectWise Folder containing documents to export.
$PWFolder = 'PowerShell\FilesToZip'

# Output file path and name. We will add to the file name which will include the .zip extension.
$OutputFilePathName = 'D:\TEMP\Export\MyFiles'

Next, we will use the Get-PWDocumentsBySearch cmdlet to select the ProjectWise documents contained within the PowerShell\FilesToZip folder.

export1

NOTE: You could pipe the results of the Get-PWDocumentsBySearch to the Export-PWDocumentFilesToZip cmldet.

# Get ProjectWise Documents to export to zip file.
$DocsToExportToZip = Get-PWDocumentsBySearch -FolderPath $PWFolder -JustThisFolder -Verbose

You can verify the number of documents by using the .Count property of the $DocsToExportToZip variable. You see we do in fact have 8 document objects.

export2

Then, we will create a splat (a special type of hashtable) with the required parameters and values.

# Splatting containing the parameter name and value pairs.
$Splat_Export = @{
    InputDocuments = $DocsToExportToZip
}
$Splat_Export.OutputFileName = "$($OutputFilePathName)_01.zip"

We are going to export the documents out three times to demonstrate the results of the optional parameters.

The first time we will not include either of the optional parameters.

# Export documents to zip replicating the folder path.
Export-PWDocumentFilesToZip @Splat_Export -Verbose | Out-Null

The second time we will  update the output file and include the -FolderPrefixToRemove parameter. We will specify ‘PowerShell’ to be removed from the prefix.

# Change the OutputFileName to use '_02_PrefixRemoved.zip'.
$Splat_Export.OutputFileName = "$($OutputFilePathName)_02_PrefixRemoved.zip"

# Export documents to zip removing the PowerShell folder from the path.
Export-PWDocumentFilesToZip @Splat_Export -FolderPrefixToRemove 'PowerShell' -Verbose | Out-Null

The third time we will update the output file again and include the -UseDMSFolders switch parameter.

# Change the OutputFileName to use '_03_DMSFolders.zip'.
$Splat_Export.OutputFileName = "$($OutputFilePathName)_03_DMSFolders.zip"

# Export documents to zip using the dmsfolder structure instead of the folder path.
Export-PWDocumentFilesToZip @Splat_Export -UseDMSFolders -Verbose | Out-Null

The following shows the results of the three exports. You see we have three separate zip files corresponding to each of the export processes.

export3

Now lets look at each one.

First, we exported out without using any parameters to the MyFiles_01.zip file. Notice the file path replicates the ProjectWise folder path of the source documents.

export4

Second, we exported out using the -FolderPrefixToRemove parameter to remove ‘PowerShell’ from the folder path to the MyFiles_02_PrefizRemoved.zip file. Notice this time, PowerShell is not included in the path.

export5

Third, we exported out using the -UseDMSFolders switch parameter to export to the dmsfolder rather than replicating the folder path to the MyFiles_03_DMSFolders.zip file.

export6

Experiment with it and have fun.

Hopefully, you find this useful. Please let me know if you have any questions or comments.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.