Install-sqmOdbcDriver Filesystem

Checks for an existing Microsoft ODBC Driver for SQL Server and, if absent, runs the silent installer (msodbcsql*.msi or msodbcsql*.exe) from the specified source path. Accepts ExitCode 3010 (reboot required) as success. Returns a status object with AlreadyInstalled, Installed, or Error.

Execution Flow

START Test-sqmDriverInstalled -DriverType ODBC [-DriverName] Status=AlreadyInstalled; return Test-Path $SourcePath Status=Error; return Locate installer: directory → Get-ChildItem -Include 'msodbcsql*.msi','msodbcsql*.exe' -Recurse | Sort Name -Desc Direct file path → Get-Item $SourcePath No installer found → Status=Error; return Run installer silently .msi → msiexec /i /quiet /norestart IACCEPTMSODBCSQLLICENSETERMS=YES .exe → Start-Process /quiet /norestart -Wait -PassThru ExitCode 0 or 3010? Status=Error; return Test-sqmDriverInstalled @checkParams (post-install verify) → $check2 ExitCode 3010 → append ' (Neustart empfohlen)' to Message Return [PSCustomObject] { Status, Version, Path, Message } DONE

Synopsis

Uses Test-sqmDriverInstalled -DriverType ODBC for both the pre-check and post-install verification. When -DriverName is provided it is forwarded to the pre-check for a more specific match. When $SourcePath is a directory, the newest matching msodbcsql*.msi or msodbcsql*.exe is selected via descending filename sort. MSI installs pass IACCEPTMSODBCSQLLICENSETERMS=YES for fully unattended execution. ExitCode 3010 (reboot required) is treated as success with a hint appended to the message.

No dbatools required. Requires local administrator rights. No CLASSPATH or registry changes are needed — the MSI/EXE registers the ODBC driver automatically in HKLM\SOFTWARE\ODBC\ODBCINST.INI.

Syntax

Install-sqmOdbcDriver
    -SourcePath <String>       # required; directory or direct path to installer
    [-DriverName <String>]     # optional: specific driver name for pre-check

Parameters

ParameterTypeDefaultDescription
-SourcePathStringRequired. Directory containing msodbcsql*.msi or *.exe, or direct path to an installer file.
-DriverNameStringOptional driver name filter for Test-sqmDriverInstalled. When omitted, the newest Microsoft SQL ODBC driver is auto-detected.

Return Value

PropertyDescription
StatusAlreadyInstalled — driver detected before install; Installed — successfully installed; Error — failure at any step.
VersionDetected driver version from Test-sqmDriverInstalled post-install, or $null.
PathDriver path as returned by Test-sqmDriverInstalled.
MessageHuman-readable status; includes (Neustart empfohlen) hint when ExitCode was 3010.

Examples

# Install from network share directory
Install-sqmOdbcDriver -SourcePath '\\srv\Treiber\ODBC'

# Install from direct MSI file
Install-sqmOdbcDriver -SourcePath 'C:\Setup\msodbcsql18.msi'

# Install and check for specific driver version
Install-sqmOdbcDriver -SourcePath '\\srv\ODBC' -DriverName 'ODBC Driver 18 for SQL Server'

# Check result
$r = Install-sqmOdbcDriver -SourcePath '\\srv\ODBC'
Write-Host "$($r.Status) v$($r.Version): $($r.Message)"