连接条件的Powershell正则表达式? [英] Powershell regex for connectionStrings?

查看:192
本文介绍了连接条件的Powershell正则表达式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某种原因,我有一个残酷的时间解析web.config文件中的连接字符串。

For some reason I'm having a brutal time parsing the connection string in the web.config file.

我已经得到了connectionString,但我试着以获取所有的值,例如

I've already gotten connectionString but I'm trying to get all the values such as the


  • 数据源

  • 初始目录

  • 用户名

  • 等...

  • Data Source
  • Initial Catalog
  • Username
  • etc...


资料来源= db.sample.com; user
id = sample-user; password = sample-password;
Catalog = sample-catalog;

Data Source=db.sample.com;user id=sample-user;password=sample-password;Initial Catalog=sample-catalog;


推荐答案

System.Data.Common.DbConnectionStringBuilder

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

输出:

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

另请参阅更多详细信息:DbConnectionStringBuilder在PowerShell中使用时不会解析

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

(这就是为什么这个有趣的语法 $ sb.set_ConnectionString(...)代替 $ sb.ConnectionString = ... )。

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

这篇关于连接条件的Powershell正则表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆