Add-OdbcDsn

Add-OdbcDsn

Adds an ODBC DSN.

Sintaxis

Parameter Set: Add0
Add-OdbcDsn [-Name] <String> -DriverName <String> -DsnType <String> [-AsJob] [-CimSession <CimSession> ] [-PassThru] [-Platform <String> ] [-SetPropertyValue <String> ] [-ThrottleLimit <Int32> ] [ <CommonParameters>]

Descripción detallada

The Add-OdbcDsn cmdlet adds an Open Database Connectivity (ODBC) data source name (DSN) to the computer. You can specify the properties of the DSN by using the SetPropertyValue parameter.

Do not use the Set-OdbcDsn cmdlet to add a new DSN.

For more information about ODBC, data source names, and drivers, see Microsoft Open Database Connectivity (ODBC) (https://msdn.microsoft.com/en-us/library/ms710252.aspx), Data Sources (https://msdn.microsoft.com/en-us/library/ms711688.aspx), and Drivers (https://msdn.microsoft.com/en-us/library/ms715383.aspx) on the Microsoft Developer Network.

Parámetros

-Name<String>

Specifies the name of an ODBC DSN. This cmdlet creates a DSN that has the name that this parameter specifies.

Alias

ninguno

¿Requerido?

true

¿Posición?

1

Valor predeterminado

ninguno

¿Aceptar canalización?

true (ByPropertyName)

¿Aceptar caracteres comodín?

false

-DsnType<String>

Specifies the type of an ODBC DSN. This cmdlet adds a DSN of the type that this parameter specifies. Los valores aceptables para este parámetro son los siguientes:

-- User
-- System

Alias

ninguno

¿Requerido?

true

¿Posición?

named

Valor predeterminado

ninguno

¿Aceptar canalización?

true (ByPropertyName)

¿Aceptar caracteres comodín?

false

-Platform<String>

Specifies the platform architecture. This cmdlet adds an ODBC DSN that belongs to the platform that this parameter specifies. Los valores aceptables para este parámetro son los siguientes:

-- 32-bit
-- 64-bit

The default value is 32-bit on a 32-bit process. The default value is 64-bit on a 64-bit process. If you run this cmdlet in a remote CIM session, this parameter refers to the platform architecture on the remote computer.

Alias

ninguno

¿Requerido?

false

¿Posición?

named

Valor predeterminado

ninguno

¿Aceptar canalización?

true (ByPropertyName)

¿Aceptar caracteres comodín?

false

-DriverName<String>

Specifies the name of a driver. This cmdlet assigns the new ODBC DSN to the driver that this parameter specifies.

Alias

ninguno

¿Requerido?

true

¿Posición?

named

Valor predeterminado

ninguno

¿Aceptar canalización?

true (ByPropertyName)

¿Aceptar caracteres comodín?

false

-SetPropertyValue<String>

Specifies an array of property values. This cmdlet specifies these property values for the ODBC DSN. Specify an array of strings of the form <key>=<value>.

Alias

ninguno

¿Requerido?

false

¿Posición?

named

Valor predeterminado

ninguno

¿Aceptar canalización?

true (ByPropertyName)

¿Aceptar caracteres comodín?

false

-PassThru

Devuelve un objeto que representa el elemento con el que está trabajando. De forma predeterminada, este cmdlet no genera ningún resultado.

Alias

ninguno

¿Requerido?

false

¿Posición?

named

Valor predeterminado

ninguno

¿Aceptar canalización?

false

¿Aceptar caracteres comodín?

false

-AsJob

Alias

ninguno

¿Requerido?

false

¿Posición?

named

Valor predeterminado

ninguno

¿Aceptar canalización?

false

¿Aceptar caracteres comodín?

false

-CimSession<CimSession>

Ejecuta el cmdlet en una sesión remota o en un equipo remoto. Escriba un nombre de equipo o un objeto de sesión, como la salida de un cmdlet New-CimSession o Get-CimSession. El valor predeterminado es la sesión actual en el equipo local.

Alias

ninguno

¿Requerido?

false

¿Posición?

named

Valor predeterminado

ninguno

¿Aceptar canalización?

false

¿Aceptar caracteres comodín?

false

-ThrottleLimit<Int32>

Especifica el número máximo de operaciones simultáneas que se pueden establecer para ejecutar el cmdlet. Si se omite este parámetro o es especifica un valor de 0, Windows PowerShell ® calcula un límite óptimo para el cmdlet en función del número de cmdlets de CIM que se estén ejecutando en el equipo. El límite solo se aplica al cmdlet actual, no a la sesión ni al equipo.

Alias

ninguno

¿Requerido?

false

¿Posición?

named

Valor predeterminado

ninguno

¿Aceptar canalización?

false

¿Aceptar caracteres comodín?

false

<CommonParameters>

Este cmdlet admite los siguientes parámetros comunes: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer y -OutVariable. Para obtener más información, consulte about_CommonParameters (https://go.microsoft.com/fwlink/p/?LinkID=113216).

Entradas

El tipo de entrada es el tipo de los objetos que se pueden canalizar al cmdlet.

Salidas

El tipo de resultado es el tipo de objetos que emite el cmdlet.

  • Microsoft.Management.Infrastructure.CimInstance#MSFT_OdbcDsn[]

Ejemplos

Example 1: Add a 32-bit ODBC User DSN

This command adds a 32-bit ODBC User DSN named MyPayroll that uses the specified 32-bit driver with the specified properties.

PS C:\> Add-OdbcDsn -Name "MyPayroll" -DriverName "Microsoft Access Driver (*.mdb, *.accdb)" -DsnType "User" -Platform "32-bit" -SetPropertyValue 'Dbq=C:\mydatabase.accdb'

Example 2: Add an ODBC System DSN

This command adds the ODBC System DSNs named MyPayroll that use SQL Server Native Client 10.0 with the specified DSN properties. Because the command does not include the Platform parameter, the platform architecture is the default, native platform.

PS C:\> Add-OdbcDsn -Name "MyPayroll" -DriverName "SQL Server Native Client 10.0" -DsnType "System" -SetPropertyValue @("Server=MyServer", "Trusted_Connection=Yes", "Database=Payroll")

Example 3: Add and store an ODBC System DSN

This command adds the ODBC System DSNs named MyPayroll that use SQL Server Native Client 10.0 with the specified DSN properties, and then stores the results in the $newDsn variable. The command includes the PassThru parameter. Without PassThru, the cmdlet does not return anything.

PS C:\> $newDsn = Add-OdbcDsn -Name "MyPayroll" -DriverName "SQL Server Native Client 10.0" -DsnType "System" -SetPropertyValue @("Server=MyServer", "Trusted_Connection=Yes", "Database=Payroll") -PassThru

Example 4: Migrates DSNs to a newer version of a driver

This example 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.

PS C:\> $dsnArr = Get-OdbcDsn -DriverName 'SQL Server Native Client 10.0'
PS C:\> foreach ($dsn in $dsnArr) {
          Remove-OdbcDsn -InputObject $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
}

Temas relacionados

Get-OdbcDsn

Remove-OdbcDsn

Set-OdbcDsn

N:Wdac