使用powershell从多个web.config文件中获取dbname
我想发出一个 powershell 命令来返回网络服务器上所有网站的连接字符串(特别是我正在寻找数据库名称值)...
所以我想看到类似
site1 dbname=Northwind
site2 的 内容dbname=Fitch
site3 dbname=DemoDB
我尝试过使用 IIS Powershell 管理单元...我想我已经接近这个了:
PS C:\Windows\system32>获取 Web 应用程序 | Get-WebConfiguration -filter /connectionStrings/*
但是...查看结果后...我的答案似乎不在那里
我对 powershell 很陌生 - 所以请原谅我的无知和缺乏经验
任何帮助表示赞赏!
谢谢!
I would like to issue a powershell command to return me the connection string (specifically I am looking for the db name value) for all the web sites on a web server...
So I would like to see something like
site1 dbname=Northwind
site2 dbname=Fitch
site3 dbname=DemoDB
I have tried using the IIS Powershell snap-in... I thought I was close with this:
PS C:\Windows\system32> Get-WebApplication | Get-WebConfiguration -filter /connectionStrings/*
but... after looking at the results... my answer doesn't appear to be in there
I am very new to powershell - so excuse my ignornance and inexperience
Any help appreciated!
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
希望这能让您开始。这只是假设 Web 应用程序的物理路径的物理路径上有一个 web.config 文件。它不会递归查找 Web 应用程序中的其他 web.config 文件。它还假设您的连接字符串位于 connectionStrings 配置元素中。
Hopefully, this will get you started. This just assumes there will be a web.config file at the physical path of the web application's physical path. It does not recurse to find other web.config files in the web application. It also assumes your connection strings are in the connectionStrings configuration element.
这篇帖子 可能会给您一个开始的想法。基本上将 web.config 文件作为 XML 文件加载,然后查找连接字符串所在的节点。
执行类似 $myFile = ([xml] Get-Content web.config) 的操作。然后,您可以将其通过管道传递给 Get-Member ( $myFile | Get-Member -MemberType 属性),开始进入文件以查看哪个节点拥有该文件。我不在电脑前,无法向您展示一些屏幕截图来进一步解释,但您可以查看此 章节 来自 PowerShell.com“Master PowerShell”电子书,很好地解释了 XML 的使用。
This post may give you an idea to start with. Basically load in the web.config file as an XML file and then just find the node where the connection string is.
Do something like $myFile = ([xml] Get-Content web.config). You can then pipe that to Get-Member ( $myFile | Get-Member -MemberType Property) to start working your way into the file to see what node has it. I'm not at a computer where I can show you some screenshots to explain it more, but you can check this chapter out from PowerShell.com "Master PowerShell" e-book that explains working with XML very well.