script to read the content of a file

Hi,
I’m new in powershell and I’d like to create a script to:

  1. read the time of the last transaction log in a sql file. This file may contain many transactions log that have been loaded:
    Ex: LOAD TRAN PS1 FROM ‘C:\PS1.TRAN.20141029.085631.000’
  2. make a difference between that time and the current time and write the result to a text file

Thank you for your help

So, PowerShell doesn’t natively have a means of reading SQL Server t-log files. You can use the SQL module’s Invoke-SQL command to execute your LOAD TRAN statement, though. Basically, whatever you’d do in a Query Window in SSMS.

You’ll need to parse that date into a DateTime object - again, it might be a lot easier just to use T-SQL for that, since T-SQL already understands that format and has a DATEDIFF() function to do date differences.

Thanks Don,
I finally found a way to do that. I used DateTime and DateDiff like you said.

Again thank you for your help