Add-OdbcDsn
Add-OdbcDsn
Adds an ODBC data source name into the system.
Syntax
Parameter Set: Add0
Add-OdbcDsn [-Name] <String> -DriverName <String> -DsnType <String> [-AsJob] [-CimSession <CimSession> ] [-PassThru] [-Platform <String> ] [-SetPropertyValue <String> ] [-ThrottleLimit <Int32> ] [ <CommonParameters>]
Detailed Description
Add-OdbcDsn adds an ODBC DSN into the system. You can specify the properties of the new DSN with the parameter SetPropertyValue.
Do not attempt to use Set-OdbcDsn to add a new DSN.
For more information about ODBC, data source names, and drivers, see Microsoft Open Database Connectivity (ODBC), Data Sources, and Drivers.
Parameters
-Name<String>
The name of the ODBC DSN to create.
Aliases |
none |
Required? |
true |
Position? |
1 |
Default Value |
none |
Accept Pipeline Input? |
true (ByPropertyName) |
Accept Wildcard Characters? |
false |
-DsnType<String>
The type of the ODBC DSN to add. Possible values are 'User' or 'System'.
Aliases |
none |
Required? |
true |
Position? |
named |
Default Value |
none |
Accept Pipeline Input? |
true (ByPropertyName) |
Accept Wildcard Characters? |
false |
-Platform<String>
The platform architecture of the ODBC DSN you are adding. Possible values are '32-bit' or '64-bit'. The default is '32-bit' on a 32-bit process and '64-bit' on a 64-bit process. This is the platform architecture on the remote machine if this command is executed in a remote CIM session.
Aliases |
none |
Required? |
false |
Position? |
named |
Default Value |
none |
Accept Pipeline Input? |
true (ByPropertyName) |
Accept Wildcard Characters? |
false |
-DriverName<String>
The name of the ODBC driver for the new ODBC DSN.
Aliases |
none |
Required? |
true |
Position? |
named |
Default Value |
none |
Accept Pipeline Input? |
true (ByPropertyName) |
Accept Wildcard Characters? |
false |
-SetPropertyValue<String>
Specifies the property values of the new ODBC DSN. Format as an array of strings where each string is: <key>=<value>.
Aliases |
none |
Required? |
false |
Position? |
named |
Default Value |
none |
Accept Pipeline Input? |
true (ByPropertyName) |
Accept Wildcard Characters? |
false |
-PassThru
Passes the object created by this cmdlet through the pipeline. By default, this cmdlet does not pass any objects through the pipeline.
Aliases |
none |
Required? |
false |
Position? |
named |
Default Value |
none |
Accept Pipeline Input? |
false |
Accept Wildcard Characters? |
false |
-AsJob
Aliases |
none |
Required? |
false |
Position? |
named |
Default Value |
none |
Accept Pipeline Input? |
false |
Accept Wildcard Characters? |
false |
-CimSession<CimSession>
Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession or Get-CimSession cmdlet. The default is the current session on the local computer.
Aliases |
none |
Required? |
false |
Position? |
named |
Default Value |
none |
Accept Pipeline Input? |
false |
Accept Wildcard Characters? |
false |
-ThrottleLimit<Int32>
Specifies the maximum number of concurrent operations that can be established to run the cmdlet. If this parameter is omitted or a value of 0
is entered, then Windows PowerShell® calculates an optimum throttle limit for the cmdlet based on the number of CIM cmdlets that are running on the computer. The throttle limit applies only to the current cmdlet, not to the session or to the computer.
Aliases |
none |
Required? |
false |
Position? |
named |
Default Value |
none |
Accept Pipeline Input? |
false |
Accept Wildcard Characters? |
false |
<CommonParameters>
This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see about_CommonParameters (https://go.microsoft.com/fwlink/p/?LinkID=113216).
Inputs
The input type is the type of the objects that you can pipe to the cmdlet.
Outputs
The output type is the type of the objects that the cmdlet emits.
- Microsoft.Management.Infrastructure.CimInstance#MSFT_OdbcDsn[]
Examples
This command adds a 32-bit ODBC User DSN named as "MyPayroll" using the specified 32-bit driver "Microsoft Access Driver (*.mdb, *.accdb)" with the specified DBQ properties. The Name parameter is positioned at 0:
PS C:\> Add-OdbcDsn MyPayroll -DriverName "Microsoft Access Driver (*.mdb, *.accdb)" -DsnType User -Platform 32-bit -SetPropertyValue 'Dbq=C:\mydatabase.accdb'
This command adds the ODBC System DSN(s) named as "MyPayroll" using SQL Server Native Client 10.0 with the specified DSN properties. Note that Platform defaults to the native platform:
PS C:\> Add-OdbcDsn MyPayroll -DriverName "SQL Server Native Client 10.0" -DsnType System -SetPropertyValue @("Server=MyServer", "Trusted_Connection=Yes", "Database=Payroll")
This command is equivalent to example 2, but it saves the newly-created System DSN object into a PowerShell variable for future use. By default, this command does not return the driver object if the "PassThru" parameter is not specified:
PS C:\> $newDsn = Add-OdbcDsn MyPayroll -DriverName "SQL Server Native Client 10.0" -DsnType System -SetPropertyValue @("Server=MyServer", "Trusted_Connection=Yes", "Database=Payroll") -PassThru
This command migrates DSNs using the SQL Server Native Client 10.0 driver to a newer version of that driver. This command works for the SQL Server Native Client ODBC driver.
C:\PS> $dsnArr = Get-OdbcDsn -DriverName 'SQL Server Native Client 10.0'
C:\PS> foreach ($dsn in $dsnArr) {
Remove-OdbcDsn $dsn
# You can change the property array as well,
# if DSN attributes have been changed in the new driver version
Add-OdbcDsn –Name $dsn.Name -DsnType $dsn.DsnType -Platform $dsn.Platform -DriverName 'SQL Server Native Client 12.0' -SetPropertyValue $dsn.PropertyValue
}
Related topics
N:Wdac