script to read the content of a file

Welcome Forums DSC (Desired State Configuration) script to read the content of a file

This topic contains 2 replies, has 2 voices, and was last updated by

2 years, 1 month ago.

  • Author
  • #60441

    Points: 0
    Rank: Member

    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

    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    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

      Points: 0
      Rank: Member

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

      Again thank you for your help

The topic ‘script to read the content of a file’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort