Last active
May 5, 2021 18:05
-
-
Save crshnbrn66/441c9e8f8464772ca189553a9186cd78 to your computer and use it in GitHub Desktop.
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
function Get-FileNameProperties | |
{ | |
param( $path = "~", | |
[switch] $Recurse, | |
[array]$Properties = ('Fullname', 'LastAccessTime', 'LastWriteTime', 'CreationTime','Owner','Size','Directory','Extension')) | |
$sortedfiles = $null | |
$files = Get-ChildItem -Recurse:$Recurse -File $path #if $recurse is true it'll recurse other wise it won't | |
$params2 = @() | |
foreach ($p in $Properties) | |
{ | |
if($p -eq 'Owner') | |
{ | |
$params2 += @{N="Owner";E={ (Get-Acl $_.FullName).Owner }} | |
} | |
elseif($p -eq 'Size' ) | |
{ | |
$params2 += @{N="Size";E={"$(($_.length / 1kb).tostring("#.#")) kb"}} | |
} | |
else | |
{ | |
$params2 += "$p" | |
} | |
} | |
$params2 | |
$sortedfiles = $files | select-object -Property $params2 | |
$sortedfiles | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment