I'm trying to copy files based on the hour of Get-Date's time stamp to match it to files that are saved from a different source in a filename_10_00.ext structure. If I use 24 hour time, I can use the hour of Get-Date to determine which file I'm looking for. (This is to run hourly backups)
This is what I have:
$current_time = Get-Date
$hour_var = $current_time.Hour
Get-ChildItem -Path \\Path\To\Source | Where-Object {
$_.Name -match "$hour_var"
} | Copy-Item -Destination \\Path\To\Destination
Can somebody tell me why it can't seem to match based on the PowerShell I've provided?
I am looking for pure PowerShell with ideally no imported modules.
Get-ChildItem -Path \\Path\To\Sourceas well as the desired and actual output ofGet-ChildItem -Path \\Path\To\Source | Where-Object {$_.Name -match "$hour_var"}.Get-ChildItem -Path \\Path\To\Sourcedoesn't produce any output, why are you surprised that nothing is being copied?