Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8594555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:13:35+00:00 2026-06-12T00:13:35+00:00

What is the correct practice on outputting to a CSV file from a loop.

  • 0

What is the correct practice on outputting to a CSV file from a loop. My goal is to check the attributes of all files matching a series of extensions that have not been accessed in over a month and output to a csv file for reading later.

it only outputs the information for the first file. and errors the following:

Add-Member : Cannot add a member with the name "FileName" because a member with that name already exists. If you want to overwrite the member a
nyway, use the Force parameter to overwrite it.
At C:\Users\claw\Desktop\checkFileAge.ps1:10 char:25
+             $out2csv | add-member <<<<  -MemberType NoteProperty -Name FileName -Value $i.fullname
    + CategoryInfo          : InvalidOperation: (@{FileName=C:\u...012 9:33:46 AM}:PSObject) [Add-Member], InvalidOperationException
    + FullyQualifiedErrorId : MemberAlreadyExists,Microsoft.PowerShell.Commands.AddMemberCommand

Here is my example:

    $out2csv = New-Object PSObject;

foreach ($i in get-childitem c:\users -recurse -include *.doc, *.xls, *.ppt, *.mdb, *.docx, *.xlsx, *.pptx, *.mdbx, *.jpeg, *.jpg, *.mov, *.avi, *.mp3, *.mp4, *.ogg) 
    {if ($i.lastaccesstime -lt ($(Get-Date).AddMonths(-1))) 
        {
            $out2csv | add-member -MemberType NoteProperty -Name FileName -Value $i.fullname
            $out2csv | add-member -MemberType NoteProperty -Name LastAccess -Value $i.LastAccessTime
        } 
    } $out2csv | Export-Csv "C:\FileAccessInformation.csv" -NoTypeInformation -Force
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:13:36+00:00Added an answer on June 12, 2026 at 12:13 am

    Try something like this. It is a bit more canonical PowerShell.

    $ext = '*.doc', '*.xls',...
    Get-ChildItem C:\Users -r -inc $ext | 
        Where {$_.LastAccessTime -lt [DateTime]::Now.AddMonths(-1)} |
        Select FullName, LastAccessTime |
        Export-Csv -NoTypeInformation -Force C:\FileAccessInformation.csv
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the best/correct practice to specify version within your source code tree? What
Correct me If I am doing wrong, I have just started to check WCF
When defining a new class within a project what is the correct/best practice for
I am looking at a practice test that doesn't have explanations about the correct
What is the correct/rails/best practice way to call media specific (i.e. print, screen, etc)
Everything works, but this is just to know the correct practice/right approach/what makes sense
Is it correct practice or valid syntax to use other tags inside a <title>
I've been wondering what's the correct practice for generating unique ids? The thing is
Is it correct/ a best practice to have a commonBean for operations that are
I'm writing my first jquery plugin and wondered what the correct/best practice way of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.