Posts

Showing posts from 2019

Use SQLCMD to run TSQL commands

I did this when I was testing the 'Last Run Status' monitor in the SQL 2016 mp and SSMS was running slow. Create a dummy job in SQL to run every few minutes and add this to the script section so the job executes successfully: select @@version Create a file called C:\temp\command.sql and add this: USE msdb ;   GO     EXEC dbo.sp_update_jobstep       @job_name = 'Test SQL agent job',       @step_id = 1,       @command =  'select * from this_will_break_it';   GO  Run it with this command: SQLCMD -S scom2016 -i command.sql You should get this returned: Changed database context to 'msdb'. You should see the health state of the job change (you won't get an alert).  Update the file with  select @@version and run it again to go back to healthy.

SQL agent jobs not discovered

By default SQL 2016 agent jobs are not discovered so the "SQL Agent Jobs" will be empty. In the Authoring pane go to  Object Discoveries  and change the scope to  SQL Server 2016 Agent Job and e nable this discovery: Name : Microsoft.SQLServer.2016.AgentJobDiscoveryRule Display Name: MSSQL 2016: Discover SQL Server 2016 Agent Jobs Target : SQL Server 2016 Agent (Microsoft.SQLServer.2016.Agent ) Bounce the HealthService on the SQL box (management server or agent) then they should appear.

Write-EventLog : % 2 output

Image
When using  Write-EventLog to write output to the Operations Manager log you get the weird ": % 2" output like this: Script example: $Healthy = 2625 $Unhealthy = 2626 $Message = "Rule Name: Test Event API Rule`r" $Log = "Operations Manager" $Source = "Health Service Script" $Warning = "Warning" $Information = "Information" Write-EventLog -LogName $Log -Source $Source -EventId $Healthy -EntryType $Information -Message $Message -Category 0 Example: I think it has something to do with the Health Service Script  source expecting 2 parameters. I read somewhere if you add in the -RawData parameter it works but you need to add binary data so not applicable for us. If you register a new source in the ops log like this: Run this: New-EventLog -LogName "Operations Manager" -Source "Event API" Then change this line in the above script: $Source = "Event API" Run it again you'll get this output: Nice and