PoshCode Archive  Artifact [e3797e0300]

Artifact e3797e030048278125d2752613de844d424ef0ee265e99e89f63b05a2de12592:

  • File Get-LastModDate.ps1 — part of check-in [fee5a66388] at 2018-06-10 13:52:18 on branch trunk — Reports the latest LastModified date of all the files within a folder. (user: dragonmc77 size: 1196)

# encoding: ascii
# api: powershell
# title: Get-LastModDate
# description: Reports the latest LastModified date of all the files within a folder.
# version: 0.1
# author: dragonmc77
# license: CC0
# x-poshcode-id: 5240
# x-archived: 2015-01-31T20:31:56
# x-published: 2015-06-14T05:04:00
#
#
param(  [string]$Path,
        [string]$LogFile = "")

$FolderList = Get-ChildItem $Path | Where-Object {$_.PSIsContainer}


foreach ($Folder in $FolderList) {
    if ($Folder.Name.ToLower() -eq "dfsrprivate") {continue}
    $LatestDate = Get-Date -Date 1/1/1940
    $Output = New-Object Object | Select LastModDate,Path
    $Output.Path = $Folder.FullName
    Get-ChildItem $Folder.Fullname -Recurse | 
        Where-Object {$_.GetType().ToString() -eq "System.IO.FileInfo"} |
        ForEach-Object {
            if ($_.LastWriteTime -gt $LatestDate) {$LatestDate = $_.LastWriteTime}
    }
	if ($LatestDate -eq (Get-Date -Date 1/1/1940)) {$LatestDate = $Folder.LastWriteTime}
    $Output.LastModDate = $LatestDate
    Write-Output $Output
    if ($LogFile -ne "") {
        Add-Content -Path $LogFile -Value "$($Output.LastModDate)   $($Output.Path)" -Force
    }
}