I am trying to recursively check if a folder does not contain any files that have been edited in the last year. Then it is inactive in this case and all of it's files are made read only. Therefore I also need to perform a check that checks if all the files in the folder, not just the inactive ones, are read only, because in that case it is already "been marked" and does not need to be included in the list of inactive folders.
Currently I have:
function FolderInactive{
Param([string]$Path)
$date = (Get-Date).AddDays(-365)
Get-ChildItem $Path -Recurse -File | ForEach-Object {
if ($_.LastWriteTime -ge $date -or $_.IsReadOnly -eq $false) {
$false
}
}
$true
}
This makes sense for the file last edited part, but it doesn't seem correct in the read only part. Should it be true or false? Should it be -or or -and? If all files are active, but one of them is read only or not it will still be marked as inactive. That doesn't seem right. I can't wrap my head around doing it in one loop.
I can of course do this in two loops, but I am dealing with big file systems and would therefore like to do it in one loop if possible.