First of all, I know there is at least 20 better solutions to do what I’m about to propose. The world is not perfect, there is still people clenching onto the olds ways of doing things. So, instead of learning from history, decommissioning PowerShell and putting it in a museum; I will explain how to use it for this use-case.

First of all, you need to Install PowerShell from a microsoft repository. So, in a Fedora Toolbox;

sudo rpm --import
curl | sudo tee /etc/yum.repos.d/microsoft.repo
sudo dnf makecache
sudo dnf install powershell

Then you need to download a SQL Connector:

You can choose a packaging option. I used .NET & Mono. In the archive, I took the 6.0 DotNet Core version (the Stable version at the time this was written). Then I grabbed the precious « MySql.Data.dll ».

Then in your .ps file;

Add-Type -Path './MySql.Data.dll'
$Connection = [MySql.Data.MySqlClient.MySqlConnection]@{ConnectionString='server=;port=61000;uid=user;pwd=password;database=databasName'}
$Command = New-Object MySql.Data.MySqlClient.MySqlCommand("YOUR SQL QUERY", $Connection)
$DataAdapter = New-Object MySql.Data.MySqlClient.MySqlDataAdapter($Command)
$DataSet = New-Object System.Data.DataSet
$RecordCount = $dataAdapter.Fill($DataSet,"data") | Out-Null
$Table=$DataSet.Tables["data"] | FT  -auto

Write-Host ($Table | Format-Table | Out-String)

And then you can play with the results contained in « Table ».

Conclusion: It take a lots of steps to do a simple thing such as reading an SQL table, but at least it’s doable. I choose not to use an ODBC connector since I got issues with it’s stability with PowerShell.