I m using this PowerShell scripts just to fetch SQL Server version as below
Get-DbaDatabase -SqlInstance "DESKTOP-6U9IKQD" | Invoke-DbaQuery -File &