Solved

Last accessed folder information

Posted on 2013-11-28
7
308 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 51

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 51

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
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)

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now