Solved

Last accessed folder information

Posted on 2013-11-28
7
314 Views
Last Modified: 2013-12-04
How to get the last access  files greater than 1 year along with size of files.
0
Comment
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 39

Expert Comment

by:footech
ID: 39684157
The following will get files that were last accessed more than a year ago.  Size is returned by default, so no need to do anything special.
$startfolder = "c:\whatever"
$age = (Get-Date).AddYears(-1)
Get-ChildItem $startfolder -Recurse | Where {$_.LastAccessTime -lt $age}

Open in new window

0
 
LVL 5

Author Comment

by:VIVEKANANDHAN_PERIASAMY
ID: 39684187
Output gives like below:
  Directory: E:\Software\SQL2008\x64\setup\sql_engine_core_inst_msi\pfiles\sqlservr\mssql.x\mssql\binn\dlltmp32


Mode                LastWriteTime     Length Name                                                                                                                                      
----                -------------     ------ ----                                                                                                                                      
-a---          4/3/2010   7:21 AM      73568 dws5mxvv.dll                                                                                                                              
-a---          4/3/2010   7:21 AM      47456 lo7viuxq.dll                                                                                                                              


    Directory: E:\Software\SQL2008\x64\setup\sql_engine_core_inst_msi\pfiles\sqlservr\mssql.x\mssql\binn\dlltmp64


Mode                LastWriteTime     Length Name                                                                                                                                      
----                -------------     ------ ----                                                                                                                                      
-a---          4/3/2010   6:27 AM      79200 4a0g_qam.dll                                                                                                                              
-a---          4/3/2010   6:27 AM      77152 a34tgahi.dll                                                                                                                              


    Directory: E:\Software\SQL2008\x64\setup\sql_engine_core_inst_msi\pfiles\sqlservr\mssql.x\mssql\binn\template


Mode                LastWriteTime     Length Name                                                                                                                                      
----                -------------     ------ ----                                                                                                                                      
-a---          4/2/2010   1:11 PM    4194304 master.mdf                                                                                                                                
-a---          4/2/2010   1:11 PM     524288 mastlog.ldf                                                                                                                              
-a---          4/2/2010   1:11 PM    1310720 model.mdf                                                                                                                                
-a---          4/2/2010   1:11 PM     524288 modellog.ldf                                                                                                                              
-a---          4/2/2010   1:11 PM   11534336 msdbdata.mdf                                                                                                                              
-a---          4/2/2010   1:11 PM     524288 msdblog.ldf  


instead i like have full pathname and size in kb and last accessed time not lastwritetime
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39684434
You just need to use Select-Object cmdlet to get the required properties..
Try..
Get-ChildItem "E:\Files" -Recurse | 
  Where {$_.LastAccessTime -lt (Get-Date).AddYears(-1) -and !($_.PSIsContainer) } |
  Select FullName,LastAccessTime,@{N="Size KB";E={"{0:N2}" -f ($_.Length /1KB)}} |
Export-Csv C:\report.csv -nti

Open in new window

0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 53

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 39684531
Not sure if you were interested in VBS, but since this question is tagged in that zone, here's an idea of what you can do there.  I typically like to send the output of scans like this to a CSV and then load in to Excel for sorting, formatting, printing, etc.  So, save the following as a VBS, and then run it passing it the starting folder for the output.  Redirect the output to a CSV file, and then open in Excel.

cscript //nologo EE28306189.vbs c:\yourfolder > report.csv

' Define needed filesystem object
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")

' Get folder name to list off the command line, make sure it's valid
If (WScript.Arguments.Count > 0) Then
    strFolder = Wscript.Arguments(0)
    If Right(strFolder, 1) = "\" Then strFolder = Left(strFolder, Len(strFolder)-1)
    If Not objFSO.FolderExists(strFolder & "\") Then
        WScript.Echo "Specified folder does not exist."
        WScript.Quit
    End If
Else
    WScript.Echo "No folder name specified to list."
    WScript.Quit
End If

' Header row
Wscript.Echo Quote("Path") & "," & Quote("Size") & "," & Quote("Accessed")

' Call recursive routine to list old files
ListFiles objFSO.GetFolder(strFolder)


' Recursively list files older than number of days specified
Sub ListFiles(objFolder)
    ' List any files older than specified time from this folder
    For Each objFile In objFolder.Files
        If DateDiff("y", objFile.DateLastAccessed, Now) > 0 Then 
            Wscript.Echo Quote(objFile.Path) & "," & objFile.Size/1024 & "," & Quote(objFile.DateLastAccessed)
        End If
    Next

    ' List all older files in any subfolders of this one
    For Each objSubFolder In objFolder.Subfolders
        ListFiles objSubFolder
    Next
End Sub

' Add surrounding double quotes to a string
Function Quote(s)
   Quote = Chr(34) & s & Chr(34)
End Function

Open in new window

~bp
0
 
LVL 5

Author Comment

by:VIVEKANANDHAN_PERIASAMY
ID: 39685225
The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 char
 i'm getting error like above.
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 39685352
Who's solution were you replying to?

Long filenames are a problem typically in any scripting language, and at best you're probably only going to be able to skip over those.

~bp
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39689750
To deal with the character limitation you may use robocopy. But with robocopy you cannot use the property. You can refer the following link to find a sample function which use robocopy. In the code you need replace /MaxAge and /MinAge with /MAXLAD and /MINLAD to use LastAccessTime instead of LastWriteTime.

http://gallery.technet.microsoft.com/scriptcenter/Get-Deeply-Nested-Files-a2148fd7
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question