Archive

Archive for March, 2012

Find All Old Files The PowerShell Way

Last week, a colleague asked for help to find files older than a certain date. For this, it appears that Symantec NetBackup has a bug where if it is performing a backup with files that are created with a date older than 01/01/1980, NetBackup performs a full system backup instead of differential. Symantec have knowledge article TECH23000 (opens in new window) about it ‘STATUS CODE 0: INCREMENTAL backups run as a FULL backup despite the last FULL having backed up all files with Status 0. The bpbkar log reports “folder <folder_name> has been created recently (since 11/9/02 11:35:32 AM). It will be backed up in full.”’

The article discusses methods of resolving this behaviour- that include performing the following command “C:\dir *.* /S /TC >C:\creation.txt” (which is incorrect and should be dir “c:\*.* /S /TC >C:\creation.txt“) but does not give any suggestion as to how to find the offending items.

Being on a Windows 2008 server, I thought that as this server is running Windows Server 2008, PowerShell is installed and would provide the easiest way. Here is the script that I cam up with:

$OldestDate = Get-Date "29/02/2012" # Set the oldest date. Enter it in the local date/time format.
$Files = @() # Define $Files variable as an empty array.
$Drives = Get-WmiObject Win32_Volume | Where-Object {($_.DriveType -eq 3) -and ($_.Label -ne "System Reserved")} # Get a list of volumes from wmi, and find drivetype 3 (local disk) that do not have the volume label "System Reserved"
foreach ($Drive in $Drives)
{ 
 Get-ChildItem -Path ($Drive.DriveLetter + "\") -Recurse | foreach {if ($_.CreationTime -le $OldestDate) {$Files += $_}
} # get each file, test if it's creation time isolder than $OldestDate and add to $files}
$Files | Format-Table FullName, CreationTime #Format $Files as a table for display. Could also Export-CSV or the like.