A PowerShell script that will lists or monitor files by
specific date and also check the size of the file on a particular folder.
It can be used to monitor newly added files and also monitor
the file size.
Or enter a specific date and lists the files.
If a shared folder suddenly runs out of space, it's good to
check which file or files are the culprit.
==========================
$xfile = Get-ChildItem -Path "D:\From XW Drive" -File |
#Get the full path, file name and the creation time of the file
Select-Object FullName, CreationTime |
Where-Object {
#convert the creation time to string to compare dates
$xfile = $_.CreationTime.Date.Month.ToString() + "/" + ($_.CreationTime).Date.day.ToString() + "/" + ($_.CreationTime).Date.Year.ToString()
$xCompareDate= "1/25/2010"
#conditional statement if files are equal to the date compared
#then do something if the same
if ($xfile -eq $xCompareDate) {
#Display or list the full path and the filename
#for files that will match the date specified on xCompareDate variable
$xfiles = $_.FullName.Length / 1mb
$xfilex = $xfiles.ToString().substring(0,5)
#write the files found and display its file size
write-host $_.FullName "==" $xfilex"MB"
}
}
#Get the full path, file name and the creation time of the file
Select-Object FullName, CreationTime |
Where-Object {
#convert the creation time to string to compare dates
$xfile = $_.CreationTime.Date.Month.ToString() + "/" + ($_.CreationTime).Date.day.ToString() + "/" + ($_.CreationTime).Date.Year.ToString()
$xCompareDate= "1/25/2010"
#conditional statement if files are equal to the date compared
#then do something if the same
if ($xfile -eq $xCompareDate) {
#Display or list the full path and the filename
#for files that will match the date specified on xCompareDate variable
$xfiles = $_.FullName.Length / 1mb
$xfilex = $xfiles.ToString().substring(0,5)
#write the files found and display its file size
write-host $_.FullName "==" $xfilex"MB"
}
}
==========================
Sample output:
D:\From XW Drive\My_Plant Layout.pdf == 3.528MB
D:\From XW Drive\My_Plant Layout.pdf == 3.528MB
You can tweak the code to suit what is needed..
Cheers!!! Hope it helps...
Comments
Post a Comment