Partager via


Set-OdbcDsn

Set-OdbcDsn

Modifies one or more ODBC data source names (DSNs). This modifies existing DSNs in the system.

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

Set-OdbcDsn configures the properties for one or more existing ODBC DSNs. You can specify the properties to add or modify with the parameter SetPropertyValue, and specify the properties to remove with the parameter RemovePropertyValue.

Use Add-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

-InputObject<CimInstance>

Modifies the ODBC DSNs represented by the specified ODBC DSN objects. Enter a variable that contains the objects, or type a command or expression that gets the objects.

Aliases

none

Required?

true

Position?

1

Default Value

none

Accept Pipeline Input?

true (ByValue)

Accept Wildcard Characters?

false

-Name<String>

The name of the ODBC DSN to set. You can use wildcard characters.

Aliases

none

Required?

true

Position?

1

Default Value

none

Accept Pipeline Input?

true (ByPropertyName)

Accept Wildcard Characters?

true

-DsnType<String>

The type of the ODBC DSN to set. Possible values are 'User', 'System' or 'All'.

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 to set. Possible values are '32-bit', '64-bit' or 'All'. 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>

This cmdlet will set the ODBC DSN using this driver only. You can use wildcard characters. The default is to set all ODBC DSNs.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

true (ByPropertyName)

Accept Wildcard Characters?

true

-SetPropertyValue<String>

Specifies the property values of the ODBC DSN that you are modifying or adding. 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

-RemovePropertyValue<String>

Specifies the property values of the ODBC DSN to be deleted. This is an array of keys to be removed.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

true (ByPropertyName)

Accept Wildcard Characters?

false

-PassThru

Passes the object modified by this cmdlet through the pipeline. By default, this cmdlet does not pass any objects through the pipeline.

Returns an object representing the set content. 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

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

-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 (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 changes the 64-bit ODBC System DSN named "MyPayroll" to use a database named as "Payroll". This example is designed for SQL Server drivers:

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

This command is similar to the previous example, but it configures a DSN on the native platform, which is the default Platform value:

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

This command changes the specified 32-bit ODBC User DSN with name equal to "MyPayroll" from using SQL Server Authentication to using Windows Authentication. (This example is designed for SQL Server drivers.) Also, it sets the Database key to "Payroll":

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

This command changes all ODBC User DSN(s) and System DSN(s) on both platforms with name matching the wildcard "*Payroll*" and that is using 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'

This command migrates the oldServer to newServer for all User DSN(s) and System DSN(s) using a driver with name started 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"

This command is equivalent to the first example but it also stores the output object in a PowerShell variable. By default, this command does not return the driver object if the "PassThru" parameter is not specified:

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

This command migrates the oldServer to newServer for all User DSN(s) and System DSN(s) using a driver with name started with "SQL Server" and uses the PowerShell variable $dsnArray.

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

Add-OdbcDsn

Get-OdbcDsn

Remove-OdbcDsn

N:Wdac