Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get File Owner/Author

Tags:

powershell

I have the below script retrieving specific file types from the C: drive and outputting specific file properties to a delimited CSV file. I would like to be able to also retrieve the file owner and authors. Any help is very much appreciated.

# PowerShell script to list the .xlsx  files under the C Drive
$Dir = get-childitem "C:" -recurse -force
$List = $Dir | where {$_.extension -eq ".xlsx"}
$List |Select-Object fullname, LastAccessTime, LastWriteTime, CreationTime |Export-Csv -path C:\Scripts\xlsx.csv -NoTypeInformation
like image 491
Christopher Adkins Avatar asked Feb 12 '17 21:02

Christopher Adkins


People also ask

How to find owner of file PowerShell?

To get the file owner using PowerShell, pass the file path to the Get-Acl cmdlet in PowerShell. Get-Acl cmdlet returns information about the file which can be used to determine the file owner.

How do I find the owner of a file in Windows?

A. The normal method would be to right click on the file in Explorer, select Properties, click the Security tab and click Ownership. This will then show the current owner and give the option to take ownership.

How do I use set-ACL in PowerShell?

To use Set-Acl , use the Path or InputObject parameter to identify the item whose security descriptor you want to change. Then, use the AclObject or SecurityDescriptor parameters to supply a security descriptor that has the values you want to apply. Set-Acl applies the security descriptor that is supplied.

How do I check the owner of a folder in Linux?

The best Linux command to find file owner is using “ls -l” command. Open the terminal then type ls -l filename in the prompt. The 3rd column is the file owner. The ls command should be available on any Linux system.


1 Answers

As soon as I posted this I was able to find a solution. I added @{N='Owner';E={$_.GetAccessControl().Owner}} to the select-object string. It now looks like this:

$List | Select-Object fullname, LastAccessTime, LastWriteTime, CreationTime, @{N='Owner';E={$_.GetAccessControl().Owner}} | Export-Csv -path C:\Scripts\xlsx.csv -NoTypeInformation
like image 73
Christopher Adkins Avatar answered Oct 07 '22 01:10

Christopher Adkins