Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find file with wildcard between a specific period

Status
Not open for further replies.

DebbieCoates_IPL

Programmer
Mar 18, 2019
2
GB
Hi, would appreciate any help

I am trying to write my first PowerShell script. I am copying files from one directory to another, between 2 times.

so far I have this

$StartDate = (Get-Date).Addminutes(-10)
$EndDate = Get-Date
$StrSource ="H:\SOURCE"
$StrTarget= "H:\TARGET"
Get-ChildItem $StrSource | Where-Object {($_.LastWriteTime.Date -ge $StartDate.Date) -and ($_.LastWriteTime.Date -le $EndDate.Date)} | Copy-Item -Destination $StrTarget

which copies all file from the source directory to the target directory, that are using the specified time period, however, I want to filter the file names so it looks for all xlsx files that begin with "Report_5", i.e. filename Report_BtestOne.xlsx , Report_BtestTwo.xlsx would both transfer, but Report_Cxxx.xlsx wouldn't, nor would Report_D.txt

Again, thank you for any help you can give me
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top