#PowerShell, #PowerWiseScripting, #ProjectWise, PWPS_DAB

HowTo: Use Add-PWSavedSearchOrGroup

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.

In this post, I will be demonstrating how to use the Add-PWSavedSearchOrGroup. This new functionality allows you to expand the functionality of your saved searches. You simply add an OR Group to an existing saved search.  Or as I will demonstrate, you can create a new saved search and add to it.  Either way, the saved search must exist to use this new cmdlet.

We will be using the following cmdlets to accomplish this task. All of the ProjectWise related cmdlets are available using the PWPS_DAB module. At the time of this post, I am using version 1.23.4.0. Take a look at the help for each of the cmdlets to become familiar with their functionality, available parameters, etc.

  • Show-PWFolderBrowserDialog
  • Add-PWSavedSearch
  • Add-PWSavedSearchOrGroup

Get Owner Project / Work Area

I will be specifying an owner project / work area for the saved search being created. We will use the Show-PWFolderBrowserDialog to select the Work Area.

<# Work Area to add saved search to. 
    Specifying Projects as the initial folder. #>
$pwWorkArea = Show-PWFolderBrowserDialog -InitialFolderPath 'Projects'

The following shows the Work Area selected within the folder browser dialog.

selectingWorkArea

Run Add-PWSavedSearch Cmdlet

Create and Populate Variables

Now, we will create and populate the variables used to create the initial saved search.

#region CREATE AND POPULATE VARIABLES

# Name of saved search to be created.
$SavedSearch = 'psSearchWithOr'

# Initial saved search variables
# Work Area subfolder to search
$pwFolderCAD = "$($pwWorkArea.FullPath)\01-WIP\CAD_Data"
# Indicates we will search all subfolders.
$SearchSubFolders = $true
# File(s) to search for.
$pwFileNameCAD = 'A111%-View%.dwg'
# Indicates we will search for originals only.
$OriginalsOnly = $true
#endregion CREATE AND POPULATE VARIABLES

Next, we will populate a Splat with the variables we created and use it to run the Add-PWSavedSearch cmdlet to create the initial saved search.

#region RUN ADD SAVED SEARCH CMDLET

$Splat_SavedSearch = @{
    OwnerProject     = $pwWorkArea
    SearchName       = $SavedSearch
    SearchFolder     = $pwFolderCAD
    SearchSubFolders = $SearchSubFolders
    FileName         = $pwFileNameCAD
    OriginalsOnly    = $OriginalsOnly
}

# Create initial saved search.
Add-PWSavedSearch @Splat_SavedSearch -Verbose
#endregion RUN ADD SAVED SEARCH CMDLET

The following shows the contents of the $Splat_SavedSearch variable prior to running the command.

splat_initial

The following shows the verbose output while creating the initial saved search.

output_intitial

The following shows the results of the initial saved search. You can see that we have four documents returned which meet the filename requirements (A111%-View%.dwg).

results_initial

Run Add-PWSavedSearchOrGroup Cmdlet

Now that we have our initial saved search created, we can add the OR Group to it.

Create and Populate Variables

Now, we will create and populate the variables used to add the OR Group to the initial saved search.

#region CREATE AND POPULATE VARIABLES

# OR Group saved search variables
#   Work Area subfolder to search
$pwFolderIncoming = "$($pwWorkArea.FullPath)\05-Incoming"
# File(s) to search for
$pwFileNameIncoming = 'S201%-View%.dwg'

#endregion CREATE AND POPULATE VARIABLES

Next, we will populate a Splat with the variables we created and use it to run the Add-PWSavedSearchOrGroup cmdlet to add to the initial saved search.

#region RUN ADD SAVED SEARCH CMDLET

$Splat_SavedSearch = @{
    SearchName       = "$($pwWorkArea.FullPath)\$SavedSearch"
    SearchFolder     = $pwFolderIncoming
    SearchSubFolders = $SearchSubFolders
    FileName         = $pwFileNameIncoming
    OriginalsOnly    = $OriginalsOnly
}

# Update saved search to include the new OR Group
Add-PWSavedSearchOrGroup @Splat_SavedSearch -Verbose

#endregion RUN ADD SAVED SEARCH CMDLET

The following shows the contents of the $Splat_SavedSearch variable prior to running the command.

splat_update

The following shows the verbose output while creating the initial saved search.

output_update

The following shows the results of the saved search after adding the OR Group. You can see that we now have seven documents returned. Three of which meet the additional filename requirements (S201%-View%.dwg).

results_updated

Saved Search Definition

The following two images show the saved search definition after the initial creation of the saved search and after adding the OR Group.

definitionInitialdefinitionAfter

Summary

Just to recap, we created an initial saved search to return documents based on folder and subfolders and file naming. This saved search returned four documents.  We then added an OR Group to the initial saved search to specify another folder and file naming requirements. After updating the saved search we received an additional three documents.


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.

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.