Export (0) Print
Expand All

Set-OdbcDsn

Updated: June 5, 2014

Applies To: Windows 8.1, Windows PowerShell 4.0, Windows Server 2012 R2

Set-OdbcDsn

Configures properties for existing ODBC DSNs.

Syntax

Parameter Set: InputObject
Set-OdbcDsn [-InputObject] <CimInstance[]> [-AsJob] [-CimSession <CimSession[]> ] [-PassThru] [-RemovePropertyValue <String[]> ] [-SetPropertyValue <String[]> ] [-ThrottleLimit <Int32> ] [-Confirm] [-WhatIf] [ <CommonParameters>]

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




Detailed Description

The Set-OdbcDsn cmdlet configures the properties for existing Open Database Connectivity (ODBC) data source names (DSNs). Specify properties to add or modify by using the SetPropertyValue parameter. Specify properties to remove by using the RemovePropertyValue parameter.

Use the Add-OdbcDsn cmdlet to add a new DSN.

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

Parameters

-InputObject<CimInstance[]>

Specifies an array of input objects. This cmdlet modifies the ODBC DSNs that the specified ODBC DSN objects represent. Specify a variable that contains the objects, or type a command or expression that gets the objects.


Aliases

Dsn

Required?

true

Position?

1

Default Value

none

Accept Pipeline Input?

True (ByValue)

Accept Wildcard Characters?

false

-Name<String>

Specifies the name of an ODBC DSN. This cmdlet modifies the DSN that this parameter specifies. You can use wildcard characters to specify more than one ODBC DSN.


Aliases

DsnName

Required?

true

Position?

1

Default Value

none

Accept Pipeline Input?

True (ByPropertyName)

Accept Wildcard Characters?

false

-DsnType<String>

Specifies the type of an ODBC DSN. This cmdlet modifies a DSN of the type that this parameter specifies. The acceptable values for this parameter are: 

-- User
-- System
-- All


Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

True (ByPropertyName)

Accept Wildcard Characters?

false

-Platform<String>

Specifies the platform architecture. This cmdlet modifies the ODBC DSN that belongs to the architecture that this parameter specifies. The acceptable values for this parameter are: 

-- 32-bit
-- 64-bit
-- All

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.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

True (ByPropertyName)

Accept Wildcard Characters?

false

-DriverName<String>

Specifies the name of a driver. This cmdlet modifies the ODBC DSN that uses the driver that this parameter specifies. You can use wildcard characters. If you do not specify this parameter, this cmdlet modifies DSNs for all drivers.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

True (ByPropertyName)

Accept Wildcard Characters?

false

-SetPropertyValue<String[]>

Specifies an array of property values. This cmdlet modifies the properties that this parameter specifies for the ODBC DSN. Specify array of strings of the form <key>=<value>.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

True (ByPropertyName)

Accept Wildcard Characters?

false

-RemovePropertyValue<String[]>

Specifies an array of property values to remove. This cmdlet removes the property values that this parameter specifies from the ODBC DSN. Specify an array of keys to remove.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

True (ByPropertyName)

Accept Wildcard Characters?

false

-PassThru

Returns an object representing the item with which you are working. By default, this cmdlet does not generate any output.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-AsJob

Runs the cmdlet as a background job. Use this parameter to run commands that take a long time to complete. The cmdlet immediately returns an object that represents the job and then displays the command prompt. You can continue to work in the session while the job completes. To manage the job, use the *-Job cmdlets. To get the job results, use the Receive-Job cmdlet. For more information about Windows PowerShell® background jobs, see about_Jobs.


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

Session

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

-Confirm

Prompts you for confirmation before running the cmdlet.


Required?

false

Position?

named

Default Value

false

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.


Required?

false

Position?

named

Default Value

false

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.

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

Example 1: Change a 64-bit ODBC DSN to use a specified database

This command changes the 64-bit ODBC System DSN named MyPayroll to use a database named Payroll. This example is designed for SQL Server drivers.


PS C:\> Set-OdbcDsn -Name "MyPayroll" -DsnType "System" -Platform "64-bit" -SetPropertyValue "Database=Payroll"

Example 2: Change a native platform ODBC DSN to use a specified database

This command changes the native platform ODBC System DSN named MyPayroll to use a database named Payroll. This example is similar to the previous example, but it does not specify the Platform parameter and, therefore, configures a DSN on the native platform.


PS C:\> Set-OdbcDsn -Name "MyPayroll" -DsnType "System" -SetPropertyValue "Database=Payroll"

Example 3: Change a User DSN to use Windows Authentication and a specified database

This command changes the specified 32-bit ODBC User DSN named MyPayroll from using SQL Server Authentication to using Windows Authentication. This example is designed for SQL Server drivers. Also, the command specifies a value of Payroll for the Database key.


PS C:\> Set-OdbcDsn -Name "MyPayroll" -DsnType "User" -Platform "32-bit" -RemovePropertyValue @("UID", "PWD") -SetPropertyValue @("Trusted_Connection=Yes", "Database=Payroll")

Example 4: Change specified DSNs to use a specified database file

This command changes all ODBC User DSNs and System DSNs on both platforms with names that contain Payroll and that use a driver named Microsoft Access Driver (*.mdb, *.accdb) to use the database file C:\payroll.accdb.


PS C:\> Set-OdbcDsn -Name "*Payroll*" -DsnType "All" -Platform "All" -DriverName "Microsoft Access Driver (*.mdb, *.accdb)" -SetPropertyValue 'Dbq=C:\payroll.accdb'

Example 5: Migrate all DSNs that use a driver with name that starts with a string

This command migrates the oldServer to newServer for all User DSNs and System DSNs that use a driver with name that starts with SQL Server.


PS C:\> Get-OdbcDsn -DriverName "SQL Server*" -DsnType "All" -Platform "All" | Where-Object{ ($_.Attribute["Server"] -eq "oldServer") } | Set-OdbcDsn -SetPropertyValue "Server=newServer"

Example 6: Change a 64-bit ODBC System DSN to use a specified database

This command changes the 64-bit ODBC System DSN named MyPayroll to use a database named Payroll, and then stores the result in the $sysDsn variable. The command includes the PassThru parameter. Without PassThru, the cmdlet does not return anything.


PS C:\> $sysDsn = Set-OdbcDsn -Name "MyPayroll" -DsnType "System" -Platform "All" -SetPropertyValue "Database=Payroll" -PassThru

Example 7: Migrates DSNs that use a driver with name that starts with a string by using a variable

This example migrates the oldServer to newServer for all User DSNs and System DSNs that use a driver with name that starts with SQL Server. The example uses the Get-OdbcDsn to get DSNs, and then store them in the $dsnArray variable.


PS C:\> $dsnArray = Get-OdbcDsn -DriverName "SQL Server*" | Where-Object{ ($_.Attribute["Server"] -eq "oldServer") }
PS C:\> Set-OdbcDsn -InputObject $dsnArray -SetPropertyValue "Server=newServer"

Related topics

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft