Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Get-ExtendedAttributes
- {
- <#
- .SYNOPSIS
- Leverages the Windows Explorer COM object to return all extended attributes related to a file.
- .DESCRIPTION
- Windows Explorer can return many extra attributes for files. This function instances a Shell.Application COM object and parses all the valid attributes for a given directory based on a file name.
- .EXAMPLE
- Get-ExtendedAttributes grad-670x376.jpg
- MD5 : C957BA24A6C971D83C132817D486BD31
- Vertical resolution : 96 dpi
- Folder path : C:\Users\aaron\My Pictures
- Date accessed : 3/12/2015 3:42 PM
- Date created : 3/12/2015 3:42 PM
- Dimensions : 670 x 376
- Height : 376 pixels
- Horizontal resolution : 96 dpi
- Owner : CONTOSO\abockel
- Perceived type : Image
- Link status : Unresolved
- Size : 10.5 KB
- Attributes : A
- Path : C:\Users\aaron\My Pictures\grad-670x376.jpg
- Folder name : My Pictures
- Shared : No
- Folder : My Pictures (C:\Users\aaron)
- Bit depth : 24
- Name : grad-670x376
- Width : 670 pixels
- Type : JPEG image
- Date modified : 3/12/2015 3:42 PM
- Filename : grad-670x376
- Computer : MEATPOPSICLE (this computer)
- Kind : Picture
- Item type : JPEG image
- Rating : Unrated
- #>
- param ([Parameter(Mandatory = $true)]$FileName,[switch]$ExcludeMD5)
- try
- {
- switch ($filename.GetType().Name)
- {
- "String" {
- $PSFileObject = gci $filename
- }
- "FileInfo" {
- if ((test-path $filename) -eq $true)
- {$PSFileObject = $filename}
- else
- {throw "Could not validate path to file object"}
- }
- default {}
- }
- }
- catch
- {
- throw $error[0]
- }
- $objShell = New-Object -ComObject Shell.Application #create a com object for windows explorer objects
- $objFolder = $objShell.namespace($PSFileObject.DirectoryName) #set the working path
- 0..266 | Foreach-object -begin {$Columns=@{} } -process {$Columns.add($objFolder.getDetailsOf($Null, $_),$_)} #create array of attributes returned from COM for given directory
- $fileCOMObject = $objFolder.ParseName($PSFileObject.Name) #filter for the specified file. The COM object returns ALL files.
- $fileObject = new-object pscustomobject
- if ($ExcludeMD5)
- {
- #excluding MD5 hash.
- }
- else
- {
- $FileHash = Get-FileHash $PSFileObject -Algorithm MD5
- $fileObject | add-member -type noteproperty -name $FileHash.Algorithm -value $FileHash.Hash
- }
- foreach ($value in $Columns.values)
- {
- $attribute = $objFolder.GetDetailsOf($fileCOMObject, $value)
- if ($attribute)
- {
- $fileObject | add-member -type noteproperty -name ($columns.keys | ?{$columns[$_] -eq $value}) -value $attribute
- }
- }
- $fileObject
- }
Add Comment
Please, Sign In to add comment