Last active
August 2, 2018 13:06
-
-
Save AspenForester/b1c476d1a49c8e12a0c741af89774e93 to your computer and use it in GitHub Desktop.
Returns one or more objects containing all 290 metadata items available for windows files.
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
<# | |
.Synopsis | |
Gets all file metadata | |
.DESCRIPTION | |
Returns one or more objects containing all 290 metadata items available for windows files. | |
This function is based on work by Ed Wilson | |
https://gallery.technet.microsoft.com/scriptcenter/c3d0ea6c-64a1-4716-a262-bcd71c9925fc#content | |
https://blogs.technet.microsoft.com/heyscriptingguy/2009/12/29/hey-scripting-guy-how-can-i-list-all-the-properties-of-a-microsoft-word-document/ | |
.EXAMPLE | |
PS C:\> Get-FileMetaData -Path c:\Users\Me\Documents | |
.EXAMPLE | |
PS C:\> "c:\Users\Me\Documents" | Get-FileMetaData | |
.EXAMPLE | |
PS C:\> Get-ChildItem -Directory -Recurse | Get-FileMetaData | Export-CSV -Path C:\MyStorage\LotsOfFileInfo.csv | |
.NOTES | |
Author: J.B. Lewis | |
Company: Hennepin County | |
Date: 7/26/2018 | |
License: MIT | |
#> | |
function Get-FileMetaData | |
{ | |
[CmdletBinding()] | |
[OutputType([pscustomobject])] | |
Param | |
( | |
# Param1 help description | |
[Parameter(ValueFromPipeline = $true, | |
Position = 0)] | |
[String[]] | |
$Path = '.\' | |
) | |
Begin | |
{ | |
#$propertyIndexes = @(0..35) + @(37..53) + @(55..143) + @(145..164) + @(167..199) + @(203..212) + @(214..290) + @(292..294) | |
$propertyIndexes = @(0..294) | |
} | |
Process | |
{ | |
$ShellObject = New-Object -ComObject Shell.Application | |
foreach ($FolderItem in $Path) | |
{ | |
$FolderItem = Resolve-Path $FolderItem | |
Write-Verbose "Folder: $($FolderItem)" | |
# Resolve-Path outputs an object, not just the path string | |
$FolderObject = $ShellObject.namespace($FolderItem.path) | |
$Items = $FolderObject.items() | |
foreach ($FileItem in $items) | |
{ | |
$PropHash = [ordered]@{} | |
$ErrorActionPreference = 'SilentlyContinue' | |
Foreach ($Index in $propertyIndexes) | |
{ | |
# How could this be made quicker? | |
$key = $FolderObject.getDetailsOf($FolderObject.items, $Index) | |
$Value = $FolderObject.getDetailsOf($FileItem, $Index) | |
Write-Verbose ('{0} : {1} = {2} ' -f $Index, $key, $value ) | |
if ($key) | |
{ | |
# if ( $key -notin $PropHash.Keys) | |
# { | |
$Prophash.Add($key, $Value) | |
# } | |
} | |
} # end foreach | |
$ErrorActionPreference = 'Continue' | |
[pscustomobject]$Prophash | |
Clear-Variable -Name PropHash | |
} # end foreach | |
} # end foreach | |
} | |
End | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment