Get-Date folder and make an action

Good morning, everyone,

I’m new to PowerShell.
I would like to do an action based on the last modification date of a directory as follows:

If the last modification of the directory is equal or superior to the last hour, write “No file for more than 1 hour”.

If the last modification of the directory is less than the last hour, write “No file for less than 1 hour”.

I have the code below :

[…]

elseif (Get-ChildItem $folder | Where {$folder.LastWriteTime -ge $Date}) {
Write-Host “Aucun fichier depuis plus d’1 heure”
exit 2
}

else {(Get-ChildItem $folder | Where {$folder.LastWriteTime -lt $Date})
Write-Host “Aucun fichier depuis moins d’ 1 heure”
exit 0
}

The exit code is for Centreon.

$Folder refers to “C:\Directory”

 

Someone have an idea ?

$folder = Get-ChildItem -Path “C:\Directory\”

If ($folder.LastWriteTime -lt (Get-Date).AddHours(-1)){
    Write-Verbose "No file less than last hour" -Verbose
} ElseIf ($folder.LastWriteTime -ge (Get-Date).AddHours(-1)) {
    Write-Verbose "No file more or equal last hour" -Verbose
}