Bentley Communities
Bentley Communities
  • Site
  • User
  • Site
  • Search
  • User
ProjectWise
  • Product Communities
ProjectWise
ProjectWise PowerShell Extensions Forum Help creating "24hr Changes" export script for a Work Area folder
    • Sign In

    • State Suggested Answer
    • Replies 3 replies
    • Answers 1 answer
    • Subscribers 65 subscribers
    • Views 426 views
    • Users 0 members are here
    • powershell
    • ProjectWise
    • pwps_dab
    • Export-PWDocuments
    • ProjectWise PowerShell Modules

    Help creating "24hr Changes" export script for a Work Area folder

    roll_n_a_bentley
    Offline roll_n_a_bentley over 1 year ago

    I'm trying to create a script that will search for any changes to files/folders made to a "Work Area" folder within a 24 hour period and export out a copy to a local folder for those changed items. This script will be executed once a day via Task Scheduler.

    I've been following this blog post as an example to set up this script, but my attempts to modify it export within the desired parameters so far haven't worked. It currently exports a copy of the ENTIRE "Work Area" folder instead of changes that were made within the last 24 hours. Please see my current PowerShell script below:

    Import-Module -Name pwps_dab
    
    cls
    
    $my_datasource="SERVER:datasource"
    $my_pw_user="administrator"
    
    $destination_local_dir="D:\pwbk\Full Backup\MAR2022"
    $destination_local_meta_dir="d:\pwbk\metadata\"
    $pwDocumentsToExport="Get-PWDocumentsBySearch -FolderID 12345 -JustThisFolder"
    $saved_search_name="List all docs updated in last 24 hours"
    
    
    try
    {
    Undo-PWLogin
    }
    catch{}
    # New-PWLogin -gui
    
    $SecurePasswordFile = 'C:\Users\XXXX\AppData\Local\Bentley\secure_pw.txt'
    
    
    $SecurePassword = Get-SecureStringFromEncryptedFile -FileName $SecurePasswordFile
    
    Write-Host "trying to login to "  $my_datasource  " User=" $my_pw_user
    
    $is_pw_logged = New-PWLogin -DatasourceName $my_datasource -UserName $my_pw_user -Password $SecurePassword 
    
    if ( -Not $is_pw_logged  )
    	{
    		#Write-Host "cannot login to "  $my_datasource  " User="  $my_pw_user
    		#exit;
    	}
    
    Write-Host "logged to "  $my_datasource  " User=" + $my_pw_user
    	
    
    
    # Populate variable with ProjectWise document objects to be exported.
    $pwDocumentsToExport = Get-PWDocumentsBySearch -FolderID 12345
    # Show the number of documents being exported.
    $pwDocumentsToExport.Count
    # Show list of document names.
    $pwDocumentsToExport | Select-Object Name
    
    
    # Local folder to export documents to.
    $exportFolder = 'D:\pwbk\Full Backup\MAR2022'
    # Open the local folder to see content.
    Explorer $exportFolder
    
    # Export documents to local folder.
    # Using splat for readability.
    $Splat_Export = @{
        InputDocuments = $pwDocumentsToExport
        OutputFolder = $exportFolder
    }
    
    #Export-PWDocuments -Searches $saved_search_name -ServerIsUTC -OutputFolder $destination_local_dir
    
    $Results = Export-PWDocuments @Splat_Export -Verbose -Searches $saved_search_name -ServerIsUTC -ExportMetadata -ExportVersions -ExportMetaDataFile $destination_local_metadata_file
    # Save-PWDocumentReport  -SearchName  $saved_search_name  -OutputFileName  $destination_local_metadata
    
    # Frees the documents which were exported. Files are no longer locked.
    $results = CheckIn-PWDocumentsOrFree -InputDocument $pwDocumentsToExport -Free -Verbose
    
    # Look at the audit trail for one of the documents.
    $pwDocumentsToExport | Select-Object -First 1 | 
    Get-PWDocumentAuditTrailRecords -SkipSecondary -Verbose | 
    Select-Object Item_Name, Action, Action_Time | Sort-Object Action_Time -Descending

    On lines "10" and "41", the "12345" is a stand-in for the actual Work Area's "Folder ID".

    I have the following versions of pwps_dab installed:

     Get-Module -Name PWPS_DAB -ListAvailable
    
    
        Directory: C:\Program Files\WindowsPowerShell\Modules
    
    
    ModuleType Version    Name                                ExportedCommands                                                      
    ---------- -------    ----                                ----------------                                                      
    Binary     1.12.5.0   pwps_dab                            {Export-PWAAMFile, Import-PWAAMFile, Export-PWDocumentsToArchive, I...
    
    
        Directory: C:\Program Files (x86)\Bentley\ProjectWise\bin\PowerShell
    
    
    ModuleType Version    Name                                ExportedCommands                                                      
    ---------- -------    ----                                ----------------                                                      
    Binary     1.12.2.0   PWPS_DAB                            {Export-PWAAMFile, Import-PWAAMFile, Export-PWDocumentsToArchive, I...
    
    
        Directory: C:\Program Files (x86)\WindowsPowerShell\Modules
    
    
    ModuleType Version    Name                                ExportedCommands                                                      
    ---------- -------    ----                                ----------------                                                      
    Binary     1.17.1.0   pwps_dab                            {Export-PWAAMFile, Import-PWAAMFile, Export-PWDocumentsToArchive, I...
    
    

    I was hoping someone can explain what I'm doing wrong and provide an example I can use to get my desired result. I'm still a PowerShell novice, so apologies in advance if I'm missing something obvious.

    Thank You.

    • Sign in to reply
    • Cancel

    Top Replies

    • Chris Andrew
      Offline Chris Andrew Wed, Mar 2 2022 1:41 PM +1
      ##### ##### ##### ##### ## ## # # # # # # # # # # ##### #### # # # # # # # # # # # # # # # # ##### ##### ##### # # #### #### ## ### #### # # # # ### ### ### #### ### ### ## # # # # # # # # # #…

    Communities
    • Home
    • Getting Started
    • Community Central
    • Products
    • Support
    • Secure File Upload
    • Feedback
    Support and Services
    • Home
    • Product Support
    • Downloads
    • Subscription Services Portal
    Training and Learning
    • Home
    • About Bentley Institute
    • My Learning History
    • Reference Books
    Social Media
    •    LinkedIn
    •    Facebook
    •    Twitter
    •    YouTube
    •    RSS Feed
    •    Email

    © 2023 Bentley Systems, Incorporated  |  Contact Us  |  Privacy |  Terms of Use  |  Cookies