Skip to content

Instantly share code, notes, and snippets.

@crshnbrn66
Last active May 5, 2021 18:05
Show Gist options
  • Save crshnbrn66/441c9e8f8464772ca189553a9186cd78 to your computer and use it in GitHub Desktop.
Save crshnbrn66/441c9e8f8464772ca189553a9186cd78 to your computer and use it in GitHub Desktop.
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