Solved

Last accessed folder information

Posted on 2013-11-28
7
317 Views
Last Modified: 2013-12-04
How to get the last access  files greater than 1 year along with size of files.
0
Comment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 40

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
IoT Devices - Fast, Cheap or Secure…Pick Two

The IoT market is growing at a rapid pace and manufacturers are under pressure to quickly provide new products. Can you be sure that your devices do what they're supposed to do, while still being secure?

 
LVL 56

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 56

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

How To Reduce Deployment Times With Pre-Baked AMIs

Even if we can't include all the files in the base image, we can sometimes include some of the larger files that we would otherwise have to download, and we can also sometimes remove the most time-consuming steps. This can help a lot with reducing deployment times.

Question has a verified solution.

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

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

615 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