I am using a script block to run a query and perform an action depending upon the results of it. Invoke-sqlcmd doesn't seem to be working inside script block. It produces blank output, whereas i put in the same command outside script block, i get the desired output.
Invoke-sqlcmd -query "Select top 1 Message from dbo.xxx order by Timestamp desc" -serverinstance "xxx/sss"
This produces the output as "Data Uploaded;Success:True" when used outside the script block. When i use within a script block, no output. i tried to use -OutVariable and get the result to a variable but no go.
The other functions such as moving and copying files within script block works. Its only this query that doesn't work.