powershell - Check files on remote computers for time stamp older than X hours and export results to CSV -
we trying run script against pile of remote computers check date stamps of files in fixed folder older 12 hours , return results csv. date range needs flexible set time of 6pm yesterday move time moves on.
$computers = get-content -path computers.txt $filepath = "c:\temp\profile" $numdays = 0 $numhours = 12 $nummins = 5 function showoldfiles($filepath, $days, $hours, $mins) { $files = $computers @(get-childitem $filepath -include *.* -recurse | {($_.lastwritetime -lt (get-date).adddays(-$days).addhours(-$hours).addminutes(-$mins)) -and ($_.psiscontainer -eq $false)}) if ($files -ne $null) { ($idx = 0; $idx -lt $files.length; $idx++) { $file = $files[$idx] write-host ("old: " + $file.name) -fore red } } } write-output $computers, $numdays, $numhours, $nummins >> computerlist.txt
you run follow script on of remote machines:
$computers = get-content -path computers.txt $logfile = "\\servername\c$\logfile.txt" $date = "12/03/2002 12:00" $limit = get-date $date $computers | %{ $filepath = "\\$_\c$\temp\profile" $files = $null $files = get-childitem -path $filepath -recurse -force | ` where-object {$_.creationtime -lt $limit } if($files -ne $null){ "-------------------------[$($_)]------------------------">> $logfile $files | foreach {$_.fullname >> $logfile} } }
this check folder given ($filepath
) files older limit given. files older limit have there full file path logged in given network location $logfile
.
Comments
Post a Comment