Quantcast
Channel: Power Query topics
Viewing all articles
Browse latest Browse all 31168

From powershell to sql

$
0
0

Hello

My problem is next:

 

I need make a query to read a database from powershell to sqlserver and after that up to powerbi online

any ideas about that.

 

this is my code

 

$SQLServer = "server"
$SQLDBName = "prueba"
$uid ="remoto"
$pwd = " "
$query = "SELECT * FROM datos WHERE Column = 'id'"

$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server = $SQLServer; Database = $SQLDBName; Integrated Security = True; User ID = $uid; Password = $pwd;"
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = $Query
$SqlCmd.Connection = $SqlConnection
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
$DataSet = New-Object System.Data.DataSet

 $endpoint = "https://api.powerbi.com/beta/1b682faf-ba6c-46c6-a1e7-74ebc6a55b1f/datasets/8cb9acd2-13a8-486d-93bc-1649d90967a2/rows?key=zgbRrKKtFnoEqxkhzbu32WsYo3hoaUbsaLjWhj7R%2B16nHCbPs9X6363Jq8P9W9I3%2BdipVvG7QgA6nV%2FuU59EoA%3D%3D"


$payload = @{
"FC210-2" =  "This put de value from sql"
}
Invoke-RestMethod -Method Post -Uri "$endpoint" -Body (ConvertTo-Json @($payload))

 

 

 

 


Viewing all articles
Browse latest Browse all 31168

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>