chgl
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
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
Hi K
Output to CSV file and then CSV file can be opened in Excel
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
}
ASKER
will this report include the file names?
ASKER
Hi Bcunney,
i tested the script and it failed
i tested the script and it failed
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Subsun - your script works well, what does the GCI and -Nti mean?
Is gci same as dir?
Is gci same as dir?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Subsun,
Below is my script so far
Now i need the last bit of the name to be last bit of the share. e.g \\fileandprint01\Shared\In formation_ Technology \IT Service 2007
so the csv name to c:\itservice2007.csv
how can i do this, thank your help :)
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
Now i need the last bit of the name to be last bit of the share. e.g \\fileandprint01\Shared\In
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
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thank you very much!! this is fantastic!
what does the [-1] mean?
what does the [-1] mean?
ASKER
how do i know give the option to delete those files?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the explanation.
I mean deleting the files
I mean deleting the files
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window