script to read the content of a file

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Nouly Nouly 7 months, 1 week ago.

  • Author
    Posts
  • #60441
    Profile photo of Nouly
    Nouly
    Participant

    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

  • #60579
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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.

    • #60624
      Profile photo of Nouly
      Nouly
      Participant

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

      Again thank you for your help

You must be logged in to reply to this topic.