Please don't ask duplicate questions. Stick with your original question since that has the script attached to it.
How to add a SQL code to a existing PS script
Sara
441
Reputation points
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