1

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 :(

2 Answers2

1

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()
Otter
  • 1,086
  • 7
  • 18
0

Previously I had an answer discussing how to retrieve basic file info, but to access Office file info, you have to do a bit more work...

Using this answer from a previous question, I made a PowerShell function to make this easy for you.

Source Here on github

Usage

Get-OfficeFileInfo  C:\temp\UsersOfabc.comDomain.xlsx 

Name             Exp                  
----             ---                  
Title                                 
Subject                               
Author                                
Keywords                              
Comments                              
Template                              
Last author      Stephen Owen         
Revision number                       
Application name Microsoft Excel      
Creation date    7/21/2021 11:30:51 AM
Last save time   7/21/2021 11:30:51 AM
Security         0                    
Category                              
Format                                
Manager                               
Company                               
Hyperlink base                        
Content type                          
Content status                        
Language                              
Document version 

Getting the specific property you want

$fileInfo = Get-OfficeFileInfo  C:\temp\UsersOfabc.comDomain.xlsx 
$dateSaved = $fileInfo | ? Name -eq "Last save time"

C:\temp\> $dateSaved.Exp

Wednesday, July 21, 2021 11:30:51 AM

FoxDeploy
  • 12,569
  • 2
  • 33
  • 48
  • 1
    The `.DateModified` is not what I am looking for. I am downloading a `.xls` file and when I download it the `.DateModified` is the download time. I am looking for the date that the file was last saved. I can see that property in the properties of the file but can't access it through PowerShell. – Charles Davis Jul 21 '21 at 15:40
  • I redid my answer, i misinterpreted the question before. – FoxDeploy Jul 21 '21 at 15:54