How to add a SQL code to a existing PS script

Sara 441 Reputation points
2024-07-01T13:52:38.3666667+00:00

I have the below sql script to check if any failover happened on the last 24 hrs and we want to use that in the existing powershell backup report script to check that condition before it reports, the below sql code only returns a timestamp

;WITH cte_HADR AS (SELECT object_name, CONVERT(XML, event_data) AS data FROM sys.fn_xe_file_target_read_file('AlwaysOn*.xel',null,null,null) WHERE object_name = 'error_reported' )

SELECT Top 1 data.value ('(/event/@timestamp)[1]','datetime') AS [timestamp] FROM cte_HADR WHERE data.value('(/event/data[@name=''error_number''])[1]','int') = 1480

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MotoX80 37,151 Reputation points
    2024-07-01T15:12:35.4133333+00:00

    Please don't ask duplicate questions. Stick with your original question since that has the script attached to it.

    https://learn.microsoft.com/en-us/answers/questions/1785022/how-to-add-a-sql-code-to-a-powershell-script

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.