4

Is it possible to Set & Get "CUSTOM" file properties with Powershell.

I am not interested in 'Extended' file properties, at least not the pre-existing extended file properties. What I am talking about is the file properties I can add through the Windows File Properties GUI dialog on the "Custom" tab.

On the Custom tab, I can create my own file property name and set its Type ( Text, Date, Number, Yes/No ) and its Value.

I am not working with Microsoft Office Documents, MP3, JPG's or other common file types. I am working with files produced from commericial application: Proficy HMI / Cimplicity, but that should not matter as the custom properties are set by Microsoft Windows, and not by the Cimplicity application. I use the Cimplicity application to create "source" code for the file ( extention is *.cim ), and then also use the app to "compile" the file into a runtime version ( *.cimrt )

My file has an extention of .cimrt. Using the File Propereties GUI dialog, I created three custom properties:

Version   : Text   :  3.1.2469
Build     : Text   : ( TFS Build name and number )
Changeset : Number :  54849

Using a hex editor, I can see that Windows writes this information into the file.

What I would really like to be able to do is to create a Powershell script that injects these 3 properties into the cimrt file.

This post has gotten me close: Enumerate file properties in PowerShell but all I can see are extended file properties.

$shell  = New-Object -COMObject Shell.Application
$myfile = Get-ChildItem  "screen.cimrt"
$file   = $myfile.Name
$path   = $myfile.DirectoryName

$shellfolder = $shell.Namespace($path)
$shellfile   = $shellfolder.ParseName($file)

The example shows looping through the property ID numbers. I did that and extended the loop to 1024 and dumped it all to the console. I did not find my new custom properties. I then said to myself, lets let the computer do the work:

 0..32767 | %{
    $value = $shellfolder.GetDetailsOf($shellfile, $_)
    if ( $value -eq 54849 ) { $_, $shellfolder.GetDetailsOf($null, $_), $shellfolder.GetDetailsOf($shellfile, $_) }
 }

54849 was the value I set for the Changeset. 32767 was a riduculously large enough number, or so I assume. The value was never found.

$shellfile | Get-Member
produced :
Name             MemberType Definition
----             ---------- ----------
ExtendedProperty Method     Variant ExtendedProperty (string)
InvokeVerb       Method     void InvokeVerb (Variant)
InvokeVerbEx     Method     void InvokeVerbEx (Variant, Variant)
Verbs            Method     FolderItemVerbs Verbs ()
Application      Property   IDispatch Application () {get}
...

I tried :

$shellfile.ExtendedProperty("Version")
$shellfile.ExtendedProperty("Changeset")
$shellfile.ExtendedProperty("Build")

and got nothing. ( or rather $null )

$shellfile.ExtendedProperty("Owner")
produced "Administrators"

$shellfile.Verbs listed the items I could invoke when I right click the file from Explorer. I tried $shellfile.InvokeVerb('Properties') and just got the same MS GUI properties dialog.

Where can I go from here?

Joe B
  • 692
  • 8
  • 18
  • 4
    (?) None of my file properties dialogs have a `Custom` tab. – Bill_Stewart Jun 24 '20 at 21:59
  • as with `Bill_Stewart`, i DO NOT see a `Custom` tab in the properties dialog of any file in windows explorer. i am using win7, but i don't recall seeing any such tab on the win1- systems i have worked on. – Lee_Dailey Jun 25 '20 at 00:20
  • Thanks. I didn't notice that the custom tab is not present on many file types. I tried several: ISO, EXE, PDF, PNG, MP4, .DOCX and my CIMRT. Only the DOCX and the CIMRT have the custom tab. I have seen blogs about accessing the extended properties on MSO documents. I dismissed these as they got the document object by creating a MSO COM object. Perhaps there is something I can discover attempting to get the object is a similar fashion. – Joe B Jun 25 '20 at 13:29
  • 2
    The "Custom" tab is most likely a custom property sheet handler (eg, Shell extension handler) -- which is an in-process COM object implemented as a DLL and invoked by Windows shell (explorer.exe) for certain registered file types. It may (or not) expose additional properties or methods allowing you to get/set the custom file properties. Personally, I'd hunt-down the DLL responsible, load it (or its corresponding .tlb file) in OLE/COM Object Viewer (oleview.exe) to examine its type library for additional COM interfaces, properties, and methods available to get/set the custom file properties. – leeharvey1 Jun 26 '20 at 13:40
  • Correct leeharvey1, the "Custom" tab is added by a property sheet handler. The custom properties I was referring to are OLE Document Properties added by MS to Office documents. Some vendors also use them, such as Cimplcity. MS provides an API, https://docs.microsoft.com/en-us/office/troubleshoot/office-suite-issues/dsofile.dll-allow-edit-document-property that can be used to create and modify these properties. I have had success writing a C# console program (exe) to add/modify custom properties. I am working on a C# Powershell module (dll) to provide PS commandlets to do the same. – Joe B Jun 30 '20 at 15:33

0 Answers0