Operations on excel file

Hello,

I have an excel file on which i need to do 2 operations:

  1. Check if the file is empty or not. I checked with this code
    if((Get-content “file.txt”) -eq $null){“File empty”}else{“File not empty”}

    and replaced an excel instead of .txt, thought the code worked for text files it dint work for excel.
  2. The data received in the excel file is sometimes old, therefore im trying to find out whether the data is correct or old by comparing it with previous sheet(the data is appended to a new sheet of the same excel file everytime). One field has the value “date” which im using to compare.

Im new to powershell please help me understand the logic.

Thanks,
Bindu

PowerShell can access and deal with Excel files in two ways. One is using the Excel application as a COM object. Francois-Xavier Cat has a great blog post on this:

http://www.lazywinadmin.com/2014/03/powershell-read-excel-file-using-com.html

The other way is if the document is a xlsx file. This is a standardize structured data which PowerShell is great at working with. Warren Frame wrote a handy PowerShell module around it:

http://ramblingcookiemonster.github.io/PSExcel-Intro/

There is Doug Finke’s xlsx module as well:

https://blogs.technet.microsoft.com/heyscriptingguy/2015/11/25/introducing-the-powershell-excel-module-2/