24/7/365 Support

Program: Add Extended File Properties to Files in PowerShell

Discussion

The Explorer shell provides useful information about a file when you click on its Properties dialog. It includes the authoring information, image information, music information, and more.

PowerShell doesn’t expose this information by default, but it is possible to obtain these properties from the Shell.Application COM object. Example 175 does just that—and adds this extended information as properties to the files returned by the GetChildItem cmdlet.

Example 175. AddExtendedFileProperties.ps1

############################################################################## ## ## AddExtendedFileProperties.ps1 ## ## Add the extended file properties normally shown in Explorer's ## "File Properties" tab. ## ## ie: ## ## PS >GetChildItem | AddExtendedFileProperties.ps1 | ## FormatTable Name,"Bit Rate" ## ##############################################################################

begin

{ ## Create the Shell.Application COM object that provides this ## functionality $shellObject = NewObject Com Shell.Application

## Store the property names and identifiers for all of the shell ## properties $itemProperties = @{

1 = "Size"; 2 = "Type"; 3 = "Date Modified"; 4 = "Date Created"; 5 = "Date Accessed"; 7 = "Status"; 8 = "Owner"; 9 = "Author"; 10 = "Title"; 11 = "Subject"; 12 = "Category"; 13 = "Pages"; 14 = "Comments"; 15 = "Copyright"; 16 = "Artist"; 17 = "Album Title"; 19 = "Track Number"; 20 = "Genre"; 21 = "Duration"; 22 = "Bit Rate"; 23 = "Protected"; 24 = "Camera Model"; 25 = "Date Picture Taken"; 26 = "Dimensions"; 30 = "Company"; 31 = "Description"; 32 = "File Version"; 33 = "Product Name"; 34 = "Product Version" }

}

process

{ ## Get the file from the input pipeline. If it is just a filename ## (rather than a real file,) piping it to the GetItem cmdlet will ## get the file it represents. $fileItem = $_ | GetItem

## Don't process directories if($fileItem.PsIsContainer) {

Example 175. AddExtendedFileProperties.ps1 (continued)

$fileItem return }

## Extract the file name and directory name $directoryName = $fileItem.DirectoryName $filename = $fileItem.Name

## Create the folder object and shell item from the COM object $folderObject = $shellObject.NameSpace($directoryName) $item = $folderObject.ParseName($filename)

## Now, go through each property and add its information as a ## property to the file we are about to return foreach($itemProperty in $itemProperties.Keys) {

$fileItem | AddMember NoteProperty $itemProperties[$itemProperty] ` $folderObject.GetDetailsOf($item, $itemProperty) }

## Finally, return the file with the extra shell information $fileItem }

Help Category:

Get Windows Dedicated Server

Only reading will not help you, you have to practice it! So get it now.

Processor RAM Storage Server Detail
Intel Atom C2350 1.7 GHz 2c/2t 4 GB DDR3 1× 1 TB (HDD SATA) Configure Server
Intel Atom C2350 1.7 GHz 2c/2t 4 GB DDR3 1× 128 GB (SSD SATA) Configure Server
Intel Atom C2750 2.4 GHz 8c/8t 8 GB DDR3 1× 1 TB (HDD SATA) Configure Server
Intel Xeon E3-1230 v2 3.3 GHz 4c/8t 16 GB DDR3 1× 256 GB (SSD SATA) Configure Server
Intel Atom C2350 1.7 GHz 2c/2t 4 GB DDR3 1× 250 GB (SSD SATA) Configure Server

What Our Clients Say