Powershell controller to connect strings?

For some reason, I have a brutal parsing of the connection string in the web.config file.

I already got connectionString, but I'm trying to get all the values ​​like

  • Data source
  • Start directory
  • Username
  • etc...

The connection string looks like this:

Data Source = db.sample.com; user id = fetch user; password = password selection; Start Directory = sample directory;

+6
source share
1 answer

Use System.Data.Common.DbConnectionStringBuilder

 $sb = New-Object System.Data.Common.DbConnectionStringBuilder $sb.set_ConnectionString('Data Source=db.sample.com;user id=sample-user;password=sample-password;Initial Catalog=sample-catalog;') $sb 

Conclusion:

 Key Value --- ----- data source db.sample.com user id sample-user password sample-password initial catalog sample-catalog 

See also more details: DbConnectionStringBuilder does not parse when used in PowerShell

(That's why this funny syntax $sb.set_ConnectionString(...) used instead of $sb.ConnectionString = ... ).

+12
source

Source: https://habr.com/ru/post/898399/


All Articles