Home > Blockchain >  Concatenate Variable with wild cards with Filter
Concatenate Variable with wild cards with Filter

Time:02-02

How could I use a Read-Host -Prompt input in a -Filter to find a job folder? The code that I am having trouble with is -Filter "'*$JobNumber*'". PowerShell version that is being used is 5.1.

Below is the code:

# Root folder and destination folder
$JobNumber = Read-Host -Prompt 'Enter in job number'
$srcRoot = 'C:\Box\Active Projects\'
# Find job number pdf file
$JobFolder = (Get-ChildItem -Path $srcRoot -Filter "'*$JobNumber*'" -Recurse -Directory -Depth 0).Fullname

CodePudding user response:

One answer that worked was updating the lines: $JobNumber = '*' (Read-Host -Prompt 'Enter in job number') '*'

and

$JobFolder = (Get-ChildItem -Path $srcRoot -Filter "$JobNumber" -Recurse -Directory -Depth 0).Fullname

  •  Tags:  
  • Related