Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 650
  • Last Modified:

Get the file ownership from .CSV file

Hi,

I wonder if this is possible with Powershell script, I need to get the owner of files which I have the list in .CSV file as the absolute folder path so that I can get the result in secondary column which list the owner of the files.

The first column of the CSV:
F:\Directory1\file1.zip
H:\Directory3\file4.docx
.
.
.
F:\Directory99\file234324.bat

The second column is none, but I'd like it to be:
Logonname1
Logonname2
.
.
.
Logonname99

Thanks.
0
Senior IT System Engineer
Asked:
Senior IT System Engineer
1 Solution
 
footechCommented:
Code is a little different depending on whether the file you already have is a CSV (and what (if any) headers are present) or just a text file with the file names.  I'm going to assume a simple text file without any commas for the input.
(Get-Content .\files.csv) | ForEach { New-Object PsObject -property @{ name = $_; owner = (Get-Acl $_).owner}} | Export-Csv files.csv -notype

Open in new window

This will write back to the original file, but you could change the file being written to with Export-CSV if you want to write to a different file and leave the original alone.
0
 
Senior IT System EngineerIT ProfessionalAuthor Commented:
Thanks !
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Tackle projects and never again get stuck behind a technical roadblock.
Join Now