powershell

Use PowerShell to edit a file's metadata (Details tab of a file in Windows file explorer)


I want to edit the "Comments" Field of a file.

I see several examples how to read the files metadata, but am not seeing how to edit the files metadata?

enter image description here


Solution

  • off the top of my head, I think you might be able to do it with by playing with the COM object

    $myFileObj = Get-Item -Path "C:\path\to\file"
    
    $shellCom = New-Object -ComObject Shell.Application
    
    $sDirectory = $shellCom.NameSpace($myFileObj.Directory.FullName)
    
    $sFile = $sDirectory.ParseName($myFileObj.Name)
    
    

    Now do a Get-Member on the $sFile object, so $sFile | Get-Member. If you see that the property Comments has a setter, you should be able to change it. It'll have {get} {set} under Definition. Setting it should be as easy as $sFile.Comments = "blah blah blah"