使用PDFContentSplit的Powershell条件脚本根据PDF名称

问题描述

我创建了一个Powershell脚本来监视特定的文件夹。在任何子目录中生成新创建的pdf时,脚本将调用PDFContentSplitSA.exe。

一切正常,只是我无法根据找到的内容弄清楚如何运行特定的.pcs脚本。作为一种解决方法,我不得不同时运行两个.pcs脚本,但这绝对不是最好的方法


$FileSystemWatcher = New-Object System.IO.FileSystemWatcher
$FileSystemWatcher | Get-Member -Type Properties,Event
$FileSystemWatcher.Path  = "C:\EpicorData\Reports"  # PDF are generated in this folder
$FileSystemWatcher.IncludeSubdirectories = $true
$FileSystemWatcher.Filter = "*.PDF" # Wildcard to only use PDF

# Calling the program to rename the PDF reports

$PDFRenameProgram = "C:\Program Files (x86)\Traction Software\PDF Content Split SA\PDFContentSplitSA.exe"  # Path to launch the PDF Content splitter program
$PDFScript1 = "C:\EpicorData\Powershell-Scripts\PDF_Renamer\PackSlip.pcs" # Rename parameters passed for Packing Slips
$PDFScript2 = "C:\EpicorData\Powershell-Scripts\PDF_Renamer\POForm.pcs" # Rename parameters passed for Purchase Orders

Register-ObjectEvent -InputObject $FileSystemWatcher  -EventName Created  -Action {

      start-process -FilePath "PDFContentSplitSA" -Verb RunAs
  
         $Src = $Event.sourceEventArgs.FullPath  # Path of the created PDF from Epicor that need to be renamed

                & $PDFRenameProgram -u"$PDFScript1" -f"$Src" -c  # Uses PDFScript1,Packing Slips remane rules
                & $PDFRenameProgram -u"$PDFScript2" -f"$Src" -c  # Uses PDFScript2,Purchase Orders rename rules
  
      Start-Sleep -s 10
      Stop-process -Name "PDFContentSplitSA" -Force

} 

我想要一个类似这样的IF语句:

如果在$ Src中找到的PDF报告名称以PACK开头,请使用$ PDFScript1 esleif如果PDF报告名称以PURCHASEORDER开头,请使用$ PDFScript2等...如果没有,则什么也不做。

我们将越来越多地使用这些.pcs脚本来重命名文件,因此我们不希望每个PDF脚本每次都使用。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)