This here is more for the benefit of me than anyone else, but  this is a super simple PowerShell script that checks connection to a SQL instance, as well as switching to a database.

It references standard ADO.NET classes so nothing else needs to be installed on the box other than .NET. So This will even work on Linux, providing .NET Core is installed of course.