Skip to content

Instantly share code, notes, and snippets.

@XPlantefeve
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save XPlantefeve/1986407d053cdef9a74f to your computer and use it in GitHub Desktop.
Save XPlantefeve/1986407d053cdef9a74f to your computer and use it in GitHub Desktop.
Exercise: answer to an old forum question.
<#
.LINK
https://social.technet.microsoft.com/Forums/scriptcenter/en-US/bfe66e89-e6ea-48e8-bcab-6f260493944e/powershell-listing-of-all-files-and-owner-to-csv
#>
# version 1. Note that "-Attributes" was not available in 2010 (PoSh2)
Get-ChildItem -Recurse -Attributes !Directory |
ForEach-Object { Add-Member -InputObject $_ -NotePropertyName Acl -NotePropertyValue (Get-Acl $_.FullName) -PassThru } |
Select-Object DirectoryName,Name,length,@{Name='Owner';Expression={$_.acl.Owner}}
# version 2, better. I discovered GetAccessControl()
Get-ChildItem -Recurse -Attributes !Directory |
Select-Object DirectoryName,Name,Length,@{Name='Owner';Expression={$_.GetAccessControl().Owner}}
# Select from an ACL attribute.
Get-ChildItem -Recurse -Attributes !Directory |
Where-Object {$_.GetAccessControl().Owner -Notlike '*Administrators' } |
Select-Object DirectoryName,Name,Length,@{Name='Owner';Expression={$_.GetAccessControl().Owner}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment