Check if remote database exists

Escaping in PowerShell or in any other scripting language is not that much fun to begin with. So if you have quotes in quotes on different shells in different systems it becomes really funny. So trust me, I am more than surprised that I just found a neat way to check, if a database exists on a remote host with PowerShell (on Windows) and SSH (to a Linux machine):

[string]::IsNullOrEmpty((ssh root@your.hostname.com 'mysql -N -e $''SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = \''databasename\'';'''))

Execute this with a replaced host- and database name in PowerShell and it tells you “False” if your database exists or “True” if not because it is checked if the string is null or empty. Maybe just flip the boolean value in the end 🙂🙃