Sets a named connection string in the .NET machine.config file
Set-DotNetConnectionString [-Name] <String> [-Value] <String> [[-ProviderName] <String>] [-Framework] [-Framework64] [-Clr2] [-Clr4] [-WhatIf] [-Confirm] [<CommonParameters>]
The connection string setting can be set in up to four different machine.config files:
Any combination of Framework and Clr switch can be used, but you MUST supply one of each.
Name | Type | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
Name | String | The name of the .net connection string to be set |
true | false | |
Value | String | The connection string to be set. |
true | false | |
ProviderName | String | The provider name for the connection string. |
false | false | |
Framework | SwitchParameter | Set the connection string in the 32-bit machine.config. |
false | false | False |
Framework64 | SwitchParameter | Set the connection string in the 64-bit machine.config |
false | false | False |
Clr2 | SwitchParameter | Set the app setting in the .NET 2.0 machine.config. This flag won't work under PowerShell 3.0. |
false | false | False |
Clr4 | SwitchParameter | Set the app setting in the .NET 4.0 machine.config. |
false | false | False |
WhatIf | SwitchParameter | false | false | ||
Confirm | SwitchParameter | false | false | ||
CommonParameters | This cmdlet supports common parameters. For more information type Get-Help about_CommonParameters . |
Set-DotNetConnectionString -Name DevDB -Value "data source=.\DevDB;Integrated Security=SSPI;" -Framework -Framework64 -Clr2 -Clr4
Sets the DevDB connection string in the following machine.config files:
%SYSTEMROOT%\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config
%SYSTEMROOT%\Microsoft.NET\Framework64\v2.0.50727\CONFIG\machine.config
%SYSTEMROOT%\Microsoft.NET\Framework\v4.0.30319\CONFIG\machine.config
%SYSTEMROOT%\Microsoft.NET\Framework64\v4.0.30319\CONFIG\machine.config
Set-DotNetConnectionString -Name DevDB -Value "data source=.\DevDB;Integrated Security=SSPI;" -Framework64 -Clr4
Sets the DevDB connection string in the %SYSTEMROOT%\Microsoft.NET\Framework64\v4.0.30319\CONFIG\machine.config
machine.config file to:
<add name="DevDB" connectionString="data source=.\DevDB;Integrated Security=SSPI;" />
Set-DotNetConnectionString -Name Prod -Value "data source=proddb\Prod;Integrated Security=SSPI" -ProviderName 'System.Data.SqlClient' -Framework -Clr2
Creates the following connection string in the %SYSTEMROOT%\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config
file:
<add name="Prod" connectionString="data source=proddb\Prod;Integrated Security=SSPI" providerName="System.Data.SqlClient" />