Last active
August 29, 2015 14:16
-
-
Save XPlantefeve/1986407d053cdef9a74f to your computer and use it in GitHub Desktop.
Exercise: answer to an old forum question.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.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