MyITGuy
4/27/2017 - 1:24 PM

PowerShell: Test-OdbcDriver

PowerShell: Test-OdbcDriver

function Test-OdbcDriver {
	[CmdletBinding(SupportsShouldProcess=$True,DefaultParameterSetName="None")]
	PARAM(
		[Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, ParameterSetName="p1")]
		[String]
		$Name
		,
	    [Parameter(Mandatory = $false, Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, ParameterSetName="p1")]
		[ValidateSet("32-bit","64-bit")] 
		[String] 
		$Platform
	)
	
	begin {
		$OSBitness = [int](Get-WmiObject -Class Win32_Processor | Select -ExpandProperty AddressWidth | Select -First 1)
		$ProcessBitness = [IntPtr]::Size * 8
		Write-Verbose "Platform: $($Platform)"
		Write-Verbose "OSBitness: $($OSBitness)"
		Write-Verbose "ProcessBitness: $($ProcessBitness)"
	}
	
	process {
		switch ($true) {
			($Platform -eq '32-bit' -and $ProcessBitness -eq 32) {
				Test-Path -Path HKLM:"SOFTWARE\ODBC\ODBCINST.INI\$($Name)" -PathType Container
			}
			($Platform -eq '32-bit' -and $ProcessBitness -eq 64) {
				Test-Path -Path HKLM:"SOFTWARE\Wow6432Node\ODBC\ODBCINST.INI\$($Name)" -PathType Container
			}
			($Platform -eq '64-bit' -and $ProcessBitness -eq 64) {
				Test-Path -Path HKLM:"SOFTWARE\ODBC\ODBCINST.INI\$($Name)" -PathType Container
			}
			default {
				$false
			}
		}
	}
	
	end {
	}
}