List Registered DB Providers using PowerShell

Background

As we prepare some of our machines for Database Application Server work, wanted to see how to programmatically discover which Database Providers are installed.

 

Code

Outline

  1. .Net Class
    • DbProviderFactories
      • Methods
        • GetFactoryClasses
          • Returns DataTable

Powershell

Script


Set-StrictMode -Version Latest;

function listProviders()
{
	Param(

			  [parameter(Mandatory=$true)]
			  [Object]
			  $objDBFactories

    )
	[int] $iPropertyIndex = 0;

	foreach($objDBFactory in $objDBFactories)
	{

	   # increment property counter
	   $iPropertyIndex = $iPropertyIndex + 1;

	   $strLog = $objDBFactory;

	   # display data
	   $strLog;			

	} 

}	

#Get Database Provider Factory
$objDBFactories = [System.Data.Common.DbProviderFactories]::GetFactoryClasses();

#listProviders $objDBFactories

$objDBFactories | Out-GridView;

"Please press any key to continue"

#Wait
$HOST.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | OUT-NULL;
$HOST.UI.RawUI.Flushinputbuffer();

Output

Output – Sample

listDBProviders_20181019_0525PM

References

  1. Microsoft
    • DbProviderFactories
      • Docs / NET / .NET API Browser / System.Data.Common / DbProviderFactories / Methods / GetFactoryClasses
        • GetFactoryClasses
          Link

 

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s