In this PowerShell command to find the owners of files in a folder,
Get-ChildItem $dir -Recurse | foreach {Get-Acl $_.fullname | select owner} | Get-Unique -AsString
Get-Unique
returns every result that is different from the one before it instead of checking the whole list. For example:
domain\user1
domain\user2
domain\user1
domain\user3
domain\user1
It should return only one of each.
From Get-Help Get-Unique
The Get-Unique cmdlet compares each item in a sorted list to the next item, eliminates duplicates, and returns only one instance of each item. The list must be sorted for the cmdlet to work properly.
To get the result you want, pipe your list through Sort-Object
prior to using Get-Unique
$list | sort | Get-Unique
This behavior is the same as the uniq
command in Unix.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.