# Get-Date folder and make an action

**URL:** <https://forums.powershell.org/t/get-date-folder-and-make-an-action/13893>\
**Category:** PowerShell Help\
**Created:** [March 2, 2020, 9:13am UTC](https://forums.powershell.org/t/get-date-folder-and-make-an-action/13893 "2020-03-02T09:13:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cookies](https://avatars.discourse-cdn.com/v4/letter/c/a9adbd/32.png) [@cookies](https://forums.powershell.org/u/cookies)\
**Post date:** [March 2, 2020, 9:13am UTC](https://forums.powershell.org/t/get-date-folder-and-make-an-action/13893/1 "2020-03-02T09:13:35Z")

</div>

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"

&nbsp;

Someone have an idea ?

---

<div class="post-metadata">

**Author:** ![random-commandline](https://avatars.discourse-cdn.com/v4/letter/r/e56c9b/32.png) [@random-commandline](https://forums.powershell.org/u/random-commandline)\
**Post date:** [March 2, 2020, 10:47am UTC](https://forums.powershell.org/t/get-date-folder-and-make-an-action/13893/2 "2020-03-02T10:47:03Z")

</div>

```
$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
}
```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:30pm UTC](https://forums.powershell.org/t/get-date-folder-and-make-an-action/13893/3 "2024-05-16T20:30:23Z")

</div>


