Created
January 27, 2021 05:12
-
-
Save krzydoug/22790dc148d71a276d422d0d8e97c44c 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-FileMetaData { | |
[cmdletbinding()] | |
Param | |
( | |
[parameter(valuefrompipeline,ValueFromPipelineByPropertyName,Position=1,Mandatory)] | |
$InputObject | |
) | |
begin | |
{ | |
$shell = New-Object -ComObject Shell.Application | |
} | |
process | |
{ | |
foreach($object in $InputObject) | |
{ | |
if($object -is [string]) | |
{ | |
try | |
{ | |
$object = Get-Item $object -ErrorAction Stop | |
} | |
catch | |
{ | |
Write-Warning "Error while processing $object : $($_.exception.message)" | |
break | |
} | |
} | |
try | |
{ | |
Test-Path $object -ErrorAction Stop | |
} | |
catch | |
{ | |
Write-Warning "Error while processing $($object.fullname) : $($_.exception.message)" | |
break | |
} | |
switch ($object) | |
{ | |
{$_ -is [System.IO.DirectoryInfo]}{ | |
write-host Processing folder $object.FullName -ForegroundColor Cyan | |
$currentfolder = $shell.namespace($object.FullName) | |
$items = $currentfolder.items() | |
} | |
{$_ -is [System.IO.FileInfo]}{ | |
write-host Processing file $object.FullName -ForegroundColor Cyan | |
$parent = Split-Path $object | |
$currentfolder = $shell.namespace($parent) | |
$items = $currentfolder.ParseName((Split-Path $object -Leaf)) | |
} | |
} | |
try | |
{ | |
foreach($item in $items) | |
{ | |
0..512 | ForEach-Object -Begin {$ht = [ordered]@{}}{ | |
if($value = $currentfolder.GetDetailsOf($item,$_)) | |
{ | |
if($propname = $currentfolder.GetDetailsOf($null,$_)) | |
{ | |
$ht.Add($propname,$value) | |
} | |
} | |
} -End {[PSCustomObject]$ht} | |
} | |
} | |
catch | |
{ | |
Write-Warning "Error while processing $($item.fullname) : $($_.exception.message)" | |
} | |
} | |
} | |
end | |
{ | |
$shell = $null | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment