Guest User

Untitled

a guest
Jun 21st, 2020
642
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Get-ExtendedAttributes
  2. {
  3.  
  4.     <#
  5.         .SYNOPSIS
  6.             Leverages the Windows Explorer COM object to return all extended attributes related to a file.
  7.         .DESCRIPTION
  8.             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.
  9.         .EXAMPLE
  10.             Get-ExtendedAttributes grad-670x376.jpg
  11.            
  12.             MD5                   : C957BA24A6C971D83C132817D486BD31
  13.             Vertical resolution   : ‎96 dpi
  14.             Folder path           : C:\Users\aaron\My Pictures
  15.             Date accessed         : 3/12/2015 3:42 PM
  16.             Date created          : 3/12/2015 3:42 PM
  17.             Dimensions            : ‪670 x 376‬
  18.             Height                : ‎376 pixels
  19.             Horizontal resolution : ‎96 dpi
  20.             Owner                 : CONTOSO\abockel
  21.             Perceived type        : Image
  22.             Link status           : Unresolved
  23.             Size                  : 10.5 KB
  24.             Attributes            : A
  25.             Path                  : C:\Users\aaron\My Pictures\grad-670x376.jpg
  26.             Folder name           : My Pictures
  27.             Shared                : No
  28.             Folder                : My Pictures (C:\Users\aaron)
  29.             Bit depth             : 24
  30.             Name                  : grad-670x376
  31.             Width                 : ‎670 pixels
  32.             Type                  : JPEG image
  33.             Date modified         : 3/12/2015 3:42 PM
  34.             Filename              : grad-670x376
  35.             Computer              : MEATPOPSICLE (this computer)
  36.             Kind                  : Picture
  37.             Item type             : JPEG image
  38.             Rating                : Unrated
  39.            
  40.     #>
  41.     param ([Parameter(Mandatory = $true)]$FileName,[switch]$ExcludeMD5)
  42.    
  43.     try
  44.     {
  45.         switch ($filename.GetType().Name)
  46.         {
  47.             "String"    {
  48.                             $PSFileObject = gci $filename
  49.                         }
  50.             "FileInfo"  {
  51.                            
  52.                             if ((test-path $filename) -eq $true)
  53.                             {$PSFileObject = $filename}
  54.                             else
  55.                             {throw "Could not validate path to file object"}
  56.                         }
  57.             default {}
  58.         }
  59.     }
  60.     catch
  61.     {
  62.         throw $error[0]
  63.     }
  64.    
  65.    
  66.     $objShell = New-Object -ComObject Shell.Application #create a com object for windows explorer objects
  67.     $objFolder = $objShell.namespace($PSFileObject.DirectoryName)  #set the working path
  68.     0..266 | Foreach-object -begin {$Columns=@{} } -process {$Columns.add($objFolder.getDetailsOf($Null, $_),$_)} #create array of attributes returned from COM for given directory
  69.     $fileCOMObject = $objFolder.ParseName($PSFileObject.Name) #filter for the specified file. The COM object returns ALL files.
  70.     $fileObject = new-object pscustomobject
  71.     if ($ExcludeMD5)
  72.         {
  73.             #excluding MD5 hash.
  74.         }
  75.         else
  76.         {
  77.             $FileHash = Get-FileHash $PSFileObject -Algorithm MD5
  78.             $fileObject | add-member -type noteproperty -name $FileHash.Algorithm -value $FileHash.Hash
  79.         }
  80.     foreach ($value in $Columns.values)
  81.     {
  82.         $attribute = $objFolder.GetDetailsOf($fileCOMObject, $value)
  83.         if ($attribute)
  84.         {
  85.             $fileObject | add-member -type noteproperty -name ($columns.keys | ?{$columns[$_] -eq $value}) -value $attribute
  86.         }
  87.     }
  88.     $fileObject
  89. }
Add Comment
Please, Sign In to add comment