Product: PowerShell Universal
Version: 3.6.4
Anyone have any luck getting this command to run even with the connection string hard-coded?
Product: PowerShell Universal
Version: 3.6.4
Anyone have any luck getting this command to run even with the connection string hard-coded?
I am attempting to read from the PSU Azure SQL Database as I have created a few tables there.
@adam any idea?
This is the error that we catch
works fine from the deskop
Maybe @potatoqualitee has seen something like this?
These seems to work but not even a raw connection string will work with dbatools… I need dbatools
$resourceURI = "https://database.windows.net/"
$tokenAuthURI = $env:MSI_ENDPOINT + "?resource=$resourceURI&api-version=2017-09-01"
$tokenResponse = Invoke-RestMethod -Method Get -Headers @{"Secret" = "$env:MSI_SECRET" } -Uri $tokenAuthURI
$accessToken = $tokenResponse.access_token
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Data Source=<REDACTED>.database.windows.net ; Initial Catalog = <REDACTED>"
$SqlConnection.AccessToken = $AccessToken
$SqlConnection.Open()
if ($SqlConnection.State -eq "Open") {
Show-UDToast -Message "Test connection successful" -Persistent
}
$sqlcmd = $SqlConnection.CreateCommand()
$query = 'SELECT name, database_id FROM sys.databases'
$sqlcmd.CommandText = $query
$adp = New-Object System.Data.SqlClient.SqlDataAdapter $sqlcmd
$data = New-Object System.Data.DataSet
$adp.Fill($data) | Out-Null
$stuff = $data.Tables
Show-UDToast -Message ('{0}' -f ( $Stuff | Out-String)) -Persistent
$SqlConnection.Close()