1

I use powershell to inventory information about our internal websites. One of the items I track is what databases the site uses. Previously, I have used PowerShell like this to get the connectionstrings:

$allConnectionStrings = (Get-Webconfiguration $sitePath -filter "connectionStrings/add")

I now have a new site that uses the configBuilders attribute (https://learn.microsoft.com/en-us/aspnet/config-builder) on the connectionStrings tag like this:

<connectionStrings configBuilders="SitecoreConnectionStringsBuilder">

and the PowerShell command throws this error:


Get-Webconfiguration : Filename: \\?\C:\inetpub\wwwroot\MySite\web.config
Line number: 2
Error: Unrecognized attribute 'configBuilders'
At C:\scripts\Get-DatabaseNamesFromIisSite.ps1:89 char:34
+ ... nStrings = (get-webconfiguration $sitePath -filter "connectionStrings ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-WebConfiguration], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.IIs.PowerShell.Provider.GetConfigurationCommand

Is there a way I can get this to work for config that uses configBuilders in PowerShell or by using a .NET Class? The solution needs to work outside of the site code--it must be accessed externally.

Imre Pühvel
  • 4,468
  • 1
  • 34
  • 49
  • look like PowerShell does not find the "configBuilders" from your connection string. did you check the iis connection string module that the connection string is ok or not. if you want to get the Configuration object you could try to use ConfigurationManager.OpenMappedExeConfiguration method, that can be used to access application settings, connection strings etc. http://web.archive.org/web/20160619143645/http://blog.thekfactor.info/posts/programatically-accessing-a-web-config/ – Jalpa Panchal May 13 '20 at 02:52
  • I was testing a working website, so I knew that the connection strings were valid. I did look into the ConfigurationManager.OpenMappedExeConfiguration method. It appears to simply skips over the connection strings in the config and returns the connection string for the built-in LocalSqlServer connection, but no others. – Daniel Govier May 13 '20 at 18:22

0 Answers0