How to add a SQL code to a existing PS script

Sara 421 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

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,456 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MotoX80 32,746 Reputation points

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

    0 comments No comments