0

I have this code whereby the objective is to find all PDF files within a folder that have been modified within x days (as input by the user).

[void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
$title = 'PDF Last Modified'
$msg   = 'Days prior:'
$text = [Microsoft.VisualBasic.Interaction]::InputBox($msg, $title)
$headers = @{Expression={$_.CreationTime};Label="File Created";width=25}, `
@{Expression={$_.LastWriteTime};Label="File Edited";width=25}, `
@{Expression={"{0}" -f $_.FullName.Split("\")[-2]};Label="Folder";width=30}, `
@{Expression={$_.Name};Label="File Name";width=50}
Get-ChildItem -Path ..\ -Recurse -Filter *.pdf | Where-Object {$_.lastwritetime -gt (Get-Date).AddDays(-$text)} | sort LastWriteTime -descending | format-table $headers  |  out-file PDFOutput-$(get-date -f yyyy-MM-dd).txt -width 300

There are two improvements that I'd like to make.

  1. Each of those PDF files is actually a form, and at the bottom of that form is a string of numbers which identify where that form needs to go. I know that I need to use itextsharp.dll to parse the PDF file; I'd like to include in the output file after "File Name" a header "Destination" and include that string from the PDF form.

  2. On the initial VB-Input window, it asks how many day prior that the script should search. I'd like to add a second input that asks for any search parameters for the title, so if the user inputs, say, "receipt", the script finds any file titled receipt.pdf (wildcards either side of it, so it would find laptop-receipt-2015-11-17.pdf).

Any help much appreciated!

0

I don't see much efffort in realizing your plans.

  • As Get-ChildItem doesn't a provide a property Destination you have to add it yourself with a calculated property.
  • save the gci results in a variable and iterate it to run your code to get the Destination on every file.
  • modify the $headers hashtable to suit your needs (Label/Expression may be abbreviated)

No time to develop the crucial itextsharp.dll code for you.

## Q:\Test\2019\03\23\SU_1416552.ps1
$Folder = (Get-Item ..).FullName

[void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')

$title = 'PDF Last Modified'
$msg   = 'Days prior:'
$DaysPrior = [Microsoft.VisualBasic.Interaction]::InputBox($msg, $title)

$title = 'PDF Name Part'
$msg   = 'String:'
$Namepart = [Microsoft.VisualBasic.Interaction]::InputBox($msg, $title)

$PdfFiles = Get-ChildItem (Join-Path $Folder ("*{0}*" -f $NamePart)) -Recurse -File  -Filter *.pdf| 
    Where-Object LastWriteTime -gt (Get-Date).AddDays(-$DaysPrior) | 
    Sort-Object  LastWriteTime -descending | 
    Select-Object -Property FullName,Name,CreationTime,LastWriteTime,
                            @{L='Destination';E={$Null}}

foreach ($PdfFile in $PdfFiles){
    ##
    ## Insert **your** code to get FormField Destination
    ##
    $PdfFile.Destination = "string of numbers"
}

$headers = @{L="File Created";width=25;E={$_.CreationTime}},
           @{L="File Edited" ;width=25;E={$_.LastWriteTime}},
           @{L="Folder"      ;width=30;E={$_.FullName.Split("\")[-2]}},
           @{L="File Name"   ;width=50;E={$_.Name}},
           @{L="Destination" ;width=30;E={$_.Destination}}

$PdfFiles | Format-Table $headers  |  
   Out-File PDFOutput-$(get-date -f yyyy-MM-dd).txt -width 300

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.