Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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