Aqui uma versão que funciona, pode ser melhorada ainda mais.
$Now = Get-Date
$TargetFolder = "C:\Temp"
$LastWrite1Min = $Now.AddMinutes(-1)
$LastWrite2Min = $Now.AddMinutes(-2)
$LastWrite3Min = $Now.AddMinutes(-3)
$i=0
$j=0
$k=0
$StringThere = "There are "
$StringOne = "Folder(s) older than 1 Minute"
$StringTwo = "Folder(s) Older than 2 Minute"
$StringThree = "Folder(s) Older than 3 Minute"
$directoryInfo = Get-ChildItem C:\Temp | Measure-Object
#$directoryInfo.count #Returns the the number folders within the directory
If ($directoryInfo.count -eq 0){
write-host "Folder is empty - Good!"
}
##################################################
If ($directoryInfo.count -ne 0)
{
write-host "Temp has at least one folder present - ... "
$Folders = get-childitem -path $TargetFolder |
Where {$_.psIsContainer -eq $true}
foreach ($Folder in $Folders)
{
if ($Folder.LastWriteTime -le $LastWrite3Min)
{
$k++
}
elseif ($Folder.LastWriteTime -le $LastWrite2Min)
{
$j++
}
elseif ($Folder.LastWriteTime -le $LastWrite1Min)
{
$i++
}
}
}#end of not zero if
#######################################################
write-host $StringThere $i $StringOne
write-host $StringThere $j $StringTwo
write-host $StringThere $k $StringThree