# Query to get a MS SQL database status.
Param(
    [string]$instName
)
 

if ($instName)
    {
        try
        {
                $DataTable = Get-EventLog -LogName Application -EntryType "Error","Warning","Information"| 
Select-Object -Property @{Name='timestamp';Expression={$_.TimeGenerated.ToString('yyyy-MM-dd-HH-mm-ss')}}, Source ,@{Name='severity';;Expression={$_.EntryType.ToString()}}, EventID ,  Message | 
Where-Object{$_.EventID -match "2516|2517|3014|3041|3134|3266|3313|3314|3315|3316|3417|3431|3443|3456|5173|5176|9004|14420|17208|17557|18204|18210|18273|35268|35269" -and $_.Source -match $instName }

$obj = [PSCustomObject] @{
    data = @(
        [PSCustomObject] $DataTable
    )
}
        }
        catch
        {
            # If our query failed, set our dataset to null
            Write-Host "Error executing query on $instName!"
            $DataTable = $null
        }
        # We get a set of database status. Append them to the base name variable.
        if ($DataTable)
        {
            Write-Host $($obj  | ConvertTo-Json)
        }
    }
