Skip to content

Instantly share code, notes, and snippets.

@rbleattler
Created March 8, 2021 15:35
Show Gist options
  • Save rbleattler/5bf5b4c2db638aff1e426b2ddb04884d to your computer and use it in GitHub Desktop.
Save rbleattler/5bf5b4c2db638aff1e426b2ddb04884d to your computer and use it in GitHub Desktop.
PowerShell Function: Get Extended File Attributes
function Get-FileAttributes {
[CmdletBinding()]
param (
[string]
$FilePath
)
begin {
Write-Debug "Enter [$($PSCmdlet.MyInvocation.MyCommand.Name)]..."
$PSBoundParameters.Keys.ForEach{
if ($PSBoundParameters.PSItem -is [string]) {
Write-Debug "$_ : $($PSBoundParameters.Item($_))"
} else {
Write-Debug "$_ : $($PSBoundParameters.Item($_).GetType())"
}
}
if ($FilePath.StartsWith('.')) {
Write-Verbose '!.!'
$FilePath = $FilePath.Remove(0, 1).Insert(0, $PWD)
}
$File = [System.IO.FileInfo]$FilePath
$shell = New-Object -ComObject Shell.Application
Write-Verbose 'Dir:'
Write-Verbose $File.Directory
$Folder = Split-Path $File.FullName
$File = Split-Path $File.FullName -Leaf
$shellfolder = $shell.Namespace($folder)
$shellfile = $shellfolder.ParseName($File)
}
process {
$Attributes = [pscustomobject]::new()
0..287 | ForEach-Object {
$PropertyName = $shellfolder.GetDetailsOf($null, $_)
$PropertyValue = $shellfolder.GetDetailsOf($shellfile, $_)
if (-not [string]::IsNullOrWhiteSpace($PropertyValue)) {
$Attributes | Add-Member -MemberType NoteProperty -Name $PropertyName -Value $PropertyValue -Force
}
}
}
end {
$Attributes
Write-Debug "Exit [$($PSCmdlet.MyInvocation.MyCommand.Name)]..."
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment