Run SQL query on the database which resides in Azure IaaS server and send the output to CSV format.
I tried with couple of options but didnot get the desired output so looking for some help here .
$scriptCode = @'
$query = "use test_MO;
SELECT * from FROM licenses"
$sql_job = Invoke-Sqlcmd -ServerInstance $servername -Query "$Query"
$sql_job
'@
$runquery = Invoke-AzVMRunCommand -ResourceGroupName $ServerRGName -VMName $ServerName -CommandId 'RunPowerShellScript' -ScriptPath "sqllicensereport.ps1" -Parameter @{servername = $servername}