Connect and run SQL commands from Sitecore PowerShell console
Did you know while working with SPE, you can easily connect with SQL db and run some queries in Sitecore itself (provided you know the name of db and tables you want to interact with).
Following is a sample query :
Import-Function -Name Invoke-SqlCommand
$connection = [Sitecore.Configuration.Settings]::GetConnectionString("master")
$query = @"
SELECT *
FROM [Db-Name].[dbo].[Table-Name]
"@
$records = Invoke-SqlCommand -Connection $connection -Query $query
Write-Host $records