Tried to think of the best subject title; however having a problem getting this done. I'll give my preferred way, but open to any best method to get this done.
I have a tsql script that is done, formatted, perfect, does what I need. I want to run this script against multiple servers, scheduled as a SQL Agent job to run every X minutes.
I was trying a flavor of OSCMD: powershell.exe Get-DbaCmsRegServer -SqlInstance instance |invoke-dbaquery -Query 'MY SCRIPT'
Yes I'm incorporating dbatools (which is deployed on all servers, and no problem when I substitute 'MY SCRIPT' for something simple like 'sp_helpdb', for example.
It's trying to add my script with multiple lines, single quotes, parameters etc. I could, but rather put the script in the agent job (unless this just isn't the best way), use -File c:\folder'MyScript.sql'
So, the ask is, how can I get it to run the way I need, and prefer? Please make some suggestions, and even better ones than I am trying to do. When I put my script in double-quotes, the job succeeds, but nothing happens, so it's not executing as intended.
Please advise better, best, workable methods to get this done. MANY THANKS!!