This is the built-in help made by Microsoft for the command 'Set-OdbcDsn', in PowerShell version 5 - as retrieved from
Windows version 'Microsoft Windows Server 2012 R2 Standard' PowerShell help files on 2016-06-23.
For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.
Configures properties for existing ODBC DSNs.
Set-OdbcDsn [-InputObject] <CimInstance[]> [-AsJob] [-CimSession <CimSession[]>] [-PassThru] [-RemovePropertyValue <String[]>] [-SetPropertyValue <String[]>] [-ThrottleLimit
<Int32>] [-Confirm] [-WhatIf] [<CommonParameters>]
Set-OdbcDsn [-Name] <String> [-AsJob] [-CimSession <CimSession[]>] [-DriverName <String>] [-PassThru] [-Platform <String>] [-RemovePropertyValue <String[]>]
[-SetPropertyValue <String[]>] [-ThrottleLimit <Int32>] -DsnType <String> [-Confirm] [-WhatIf] [<CommonParameters>]
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.
<
Online Version: http://go.microsoft.com/fwlink/p/?linkid=287611
Add-OdbcDsn
Get-OdbcDsn
Remove-OdbcDsn
N:Wdac
<
Example 1: Change a 64-bit ODBC DSN to use a specified database
PS C:\> Set-OdbcDsn -Name "MyPayroll" -DsnType "System" -Platform "64-bit" -SetPropertyValue "Database=Payroll"
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.
Example 2: Change a native platform ODBC DSN to use a specified database
PS C:\> Set-OdbcDsn -Name "MyPayroll" -DsnType "System" -SetPropertyValue "Database=Payroll"
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.
Example 3: Change a User DSN to use Windows Authentication and a specified database
PS C:\> Set-OdbcDsn -Name "MyPayroll" -DsnType "User" -Platform "32-bit" -RemovePropertyValue @("UID", "PWD") -SetPropertyValue @("Trusted_Connection=Yes",
"Database=Payroll")
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.
Example 4: Change specified DSNs to use a specified database file
PS C:\> Set-OdbcDsn -Name "*Payroll*" -DsnType "All" -Platform "All" -DriverName "Microsoft Access Driver (*.mdb, *.accdb)" -SetPropertyValue 'Dbq=C:\payroll.accdb'
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.
Example 5: Migrate all DSNs that use a driver with name that starts with a string
PS C:\> Get-OdbcDsn -DriverName "SQL Server*" -DsnType "All" -Platform "All" | Where-Object{ ($_.Attribute["Server"] -eq "oldServer") } | Set-OdbcDsn -SetPropertyValue
"Server=newServer"
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.
Example 6: Change a 64-bit ODBC System DSN to use a specified database
PS C:\> $sysDsn = Set-OdbcDsn -Name "MyPayroll" -DsnType "System" -Platform "All" -SetPropertyValue "Database=Payroll" -PassThru
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.
Example 7: Migrates DSNs that use a driver with name that starts with a string by using a variable
PS C:\> $dsnArray = Get-OdbcDsn -DriverName "SQL Server*" | Where-Object{ ($_.Attribute["Server"] -eq "oldServer") }
PS C:\> Set-OdbcDsn -InputObject $dsnArray -SetPropertyValue "Server=newServer"
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.