I have tried without success but I suspect I have many errors at the moment. However, can anyone tell me if it is possible to separate PowerShell scripts across a series of SQL Server Agent job steps, i.e.
Job 1 Step 1 --> declare & assign a variable
Job 1 Step 2 --> use variable in a query/command
For example I am trying build a query here
powershell.exe -ExecutionPolicy Bypass -Command ' $query = ''select BackupFile from MyDB.dbo.tbl'''
and use it in this command here:
powershell.exe -ExecutionPolicy Bypass -Command ' $res = Invoke-Sqlcmd2 -ServerInstance myserver -Query $query | select-object -expand BackupFile'
I'm using basic steps to get the idea for something complicated.
Thank you for your help!