< Back

Set-CDotNetConnectionString

Sun Jan 12, 2020 11:08 pm

NAME Set-CDotNetConnectionString



SYNOPSIS

Sets a named connection string in the .NET machine.config file





SYNTAX

Set-CDotNetConnectionString [-Name] <String> [-Value] <String> [[-ProviderName] <String>] [-Framework]

[-Framework64] [-Clr2] [-Clr4] [-WhatIf] [-Confirm] [<CommonParameters>]





DESCRIPTION

The connection string setting can be set in up to four different machine.config files:



* .NET 2.0 32-bit (switches -Clr2 -Framework)

* .NET 2.0 64-bit (switches -Clr2 -Framework64)

* .NET 4.0 32-bit (switches -Clr4 -Framework)

* .NET 4.0 64-bit (switches -Clr4 -Framework64)



Any combination of Framework and Clr switch can be used, but you MUST supply one of each.





PARAMETERS

-Name <String>

The name of the .net connection string to be set



Required? true

Position? 1

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Value <String>

The connection string to be set.



Required? true

Position? 2

Default value

Accept pipeline input? false

Accept wildcard characters? false



-ProviderName <String>

The provider name for the connection string.



Required? false

Position? 3

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Framework [<SwitchParameter>]

Set the connection string in the 32-bit machine.config.



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-Framework64 [<SwitchParameter>]

Set the connection string in the 64-bit machine.config



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-Clr2 [<SwitchParameter>]

Set the app setting in the .NET 2.0 machine.config. This flag won't work under PowerShell 3.0.



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-Clr4 [<SwitchParameter>]

Set the app setting in the .NET 4.0 machine.config.



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-WhatIf [<SwitchParameter>]



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Confirm [<SwitchParameter>]



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



-------------------------- EXAMPLE 1 --------------------------



>Set-CDotNetConnectionString -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`









-------------------------- EXAMPLE 2 --------------------------



>Set-CDotNetConnectionString -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;" />









-------------------------- EXAMPLE 3 --------------------------



PS C:\\>Set-CDotNetConnectionString -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" />











RELATED LINKS

Set-CDotNetAppSetting

Remove-CDotNetAppSetting