#Database Instance connectivity test $dbhostname = 'yourservername' $dbinstance = 'DBInstance' $dbname = 'yourDBname' $username = "DB user name" $password = "DB user password" $cs = "Server=$dbhost\$dbinst;Database=$dbname;User Id=$username;" + "Password=$password;" $test = New-Object -COM 'ADODB.Connection' $test.ConnectionString = $cs try { $test.Open() if ($test.State -eq 1) { 'connected' $test.Close() } else { 'not connected' } } catch { 'not connected' }In the above script, you just need to provide the database name, Database hostname, DB username and password, make sure you have all the privileges to test the DB connection. This script is really helpful when you have more number of servers and databases, it is really important to validate the database connection and connectivity after any change to make sure DB functionality is available. Thank you for reading this article, if you have any questions please let us know. Thank you for visiting my site, for any scripts in these articles you are testing please make sure you have tested this script in our lower environment before you run in production.
Leave a Reply Cancel reply