Мне все еще нужно провести рефакторинг и изменить несколько вещей, но, похоже, это работает.
[CmdletBinding()]
param(
$Path = "C:\Users\<username>\Desktop\Archive",
$Year = [DateTime]::Today.AddDays(-1).Year,
$Month = [DateTime]::Today.AddDays(-1).Month,
$strMonth = ([String]$Month).PadLeft(2,'0'),
$Day = ([DateTime]::Today.AddDays(-1).Day),
$strDay = ([String]$Day).PadLeft(2,'0'),
$Date = "$Year" + "$strMonth" + "$strDay",
$Hours = @(
"00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11",
"12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23"
),
$strHours = $Hours.ToString().PadLeft(2,'0'),
$FilePattern = @("850_" + $Date + "*.txt"),
$Files = (Get-ChildItem -Path $Path -Include $FilePattern -Recurse |
Select-Object -ExpandProperty CreationTime | Get-Date -f "HH")
)
ForEach ($Hour in $Hours) {
if ($Hour -notin $Files) {
Write-Host "There's no file present for $Hour o'clock for $Date."
} else {
Write-Host "There's at least one file for $Hour o'clock for $Date."
}
}