Link to home
Start Free TrialLog in
Avatar of chgl
chglFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Powershell find old files and insert them on excel

HI Guys,

I need to find files that havent been accesses for a month on one of our shared drive and then put the filenames in an excel report, how can i do this?

Regards,
K
Avatar of SubSun
SubSun
Flag of India image

Try..
GCI '\\Server\Share' -Recurse | 
	?{$_.LastAccessTime -le (Get-date).AddMonths(-1)} | 
  Select FullName,CreationTime,LastAccessTime,LastWriteTime |
Export-Csv \\Server\Share\report.csv -NTI

Open in new window

Hi K
Output to CSV file and then CSV file can be opened in Excel

$pathtocheck = "\\share\folder"


$files = get-childitem $pathtocheck -Recurse

Foreach ($f in $files)

{

$access = $f | % {(get-date) – $_.LastAccessTime } 
if ($access.days -le 30) 
{ 

	$outputfilename = ( "c:\30dayReport.csv") 
	#$outputfilename 
	$f |format-table -property Fullname |out-file $outputfilename -append 

} 

Open in new window

Avatar of chgl

ASKER

will this report include the file names?
Avatar of chgl

ASKER

Hi Bcunney,

i tested the script and it failed
SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chgl

ASKER

Subsun - your script works well, what does the GCI and -Nti mean?

Is gci same as dir?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chgl

ASKER

Hi Subsun,

Below is my script so far

$pathname = Read-Host "Please Enter Path Name: "
GCI $pathname -Recurse | 
	?{$_.LastAccessTime -le (Get-date).AddMonths(-1)} | 
  Select FullName,CreationTime,LastAccessTime,LastWriteTime |
Export-Csv c:\TrainingDivisionReport.csv -NTI 

Open in new window


Now i need the last bit of the name to be last bit of the share. e.g \\fileandprint01\Shared\Information_Technology\IT Service 2007

so the csv name to c:\itservice2007.csv

how can i do this, thank your help :)
$pathname = Read-Host "Please Enter Path Name: "
GCI $pathname -Recurse | 
	?{$_.LastAccessTime -le (Get-date).AddMonths(-1)} | 
  Select FullName,CreationTime,LastAccessTime,LastWriteTime |
Export-Csv c:\TrainingDivisionReport.csv -NTI 

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chgl

ASKER

thank you very much!! this is fantastic!

what does the [-1] mean?
Avatar of chgl

ASKER

how do i know give the option to delete those files?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chgl

ASKER

Thanks for the explanation.

I mean deleting the files
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial