powershellxlsfile-properties

Accessing the "Date Last Saved" using PowerShell


I am attempting to access the Date Last Saved of an xls file using PowerShell. It is in the details page and is more of a hidden attribute of the file. Pic attached for reference.

Date Last Saved

EDIT: Thank you for the help. Both solutions work but I am in a constricted language mode so I can't use them :(


Solution

  • Went down a bit of a rabbit hole for this one but I found the below.

    The attribute is not part of the file properties. It is part of the worksheets properties (as are many attributes).

    Full credit goes to Ed Wilson and Craig Liebendorfer, Scripting Guys - https://devblogs.microsoft.com/scripting/hey-scripting-guy-how-can-i-read-microsoft-excel-metadata/

    $excel = New-Object -ComObject Excel.Application
    $excel.Visible = $false
    $workbook = $excel.Workbooks.Open("C:\temp\Test.xlsx")
    $binding = "System.Reflection.BindingFlags" -as [type]
    
    Foreach($property in $workbook.BuiltInDocumentProperties){
        if ([System.__ComObject].invokemember("name",$binding::GetProperty,$null,$property,$null) -eq "Last save time"){
            [System.__ComObject].invokemember("value",$binding::GetProperty,$null,$property,$null)
        }
    }
    $excel.quit()