#PowerShell, #PowerWiseScripting, #ProjectWise, PWPS_DAB

How To: Import Documents from a Zip File into ProjectWise Using PowerShell

With the release of PWPS_DAB module version 1.6.1.0, we now have the ability to import the contents of a zip file directly into a ProjectWise folder. This is accomplished using the Import-PWDocumentsFromZip PowerShell cmdlet.

It is a fairly straight forward process. We will begin with a zip file containing a number of Excel spreadsheets.

zip1

First things first, take a look at the help for the Import-PWDocumentsFromZip cmdlet to familiarize yourself with the available parameters, etc.

Get-Help Import-PWDocumentsFromZip -Full

This cmdlet has a few required parameters that we will need to deal with. There are a few other optional parameters available which will not be covered in this post.

  • InputFileName
  • ParentPWFolderPath
  • StorageArea

Now, we will create and populate a few variables with the file path and name of the zip file to import from and the target ProjectWise folder. We will be using the same storage area as the target ProjectWise folder.

# Path and file name of the zip file importing from.
$ZipFileToImport = "D:\temp\reporting\PW_Reports.zip"
# ProjectWise folder to import documents into.
$ProjectWiseFolder = "PowerShell\FilesFromZip"

Next, we will use the Get-PWFolders cmdlet to get the ProjectWise folder object for the specified folder.

NOTE: You could simply pass the value of the ProjectWiseFolder variable to the Import-PWDocumentsFromZip cmdlet. However, as previously stated, we will be using the same storage area as the target ProjectWise folder.

# ProjectWise Folder object for the folder to import the documents into.
$PWFolder_Object = Get-PWFolders -FolderPath $ProjectWiseFolder -JustOne -Verbose

zip2

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_Import = @{
    InputFileName = $ZipFileToImport
    ParentPWFolderPath = $PWFolder_Object.FullPath
    StorageArea = $PWFolder_Object.Storage
}

Finally, we can run the Import-PWDocumentsFromZip cmdlet using the contents of the splat. ProjectWise Document objects will be returned for each of the new documents  created within the ProjectWise folder.

# The new document objects will be returned.
$ImportedDocuments = Import-PWDocumentsFromZip @Splat_Import -Verbose

You can see that each of the Excel files were imported into the specified ProjectWise folder.

zip3

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 )

Google photo

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

Twitter picture

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

Facebook photo

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

Connecting to %s