首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Powershell修改Web.config mailSettings

Powershell修改Web.config mailSettings
EN

Stack Overflow用户
提问于 2014-05-30 23:18:10
回答 1查看 789关注 0票数 2

我使用RedGate的部署管理器进行部署。我需要使用powershell脚本作为部署的一部分来更改这一点:

代码语言:javascript
复制
<system.net>
    <mailSettings>
        <smtp from="test@test.com">
            <network host="mailtrap.io" userName="masked" password="masked" port="2525" enableSsl="false" />            
        </smtp>
    </mailSettings>
</system.net>

到这里来生产:

代码语言:javascript
复制
<system.net>
    <mailSettings>
        <smtp from="catalyst@datafinch.com">
            <network host="pod51010.outlook.com" userName="someuser" password="somepassword" port="587" enableSsl="true" />
        </smtp>
    </mailSettings>
</system.net>

我对powershell没有任何经验,不知道从何说起。有人能提供一些见解吗?

EN

回答 1

Stack Overflow用户

发布于 2014-05-30 23:59:33

我想通了:

代码语言:javascript
复制
 #Set the Connection String and the path to web.config (or any config file for that matter)
 $webConfigPath = "web.config"

 # Get the content of the config file and cast it to XML and save a backup copy labeled .bak followed by the date
 $xml = [xml](get-content $webConfigPath)     

 $root = $xml.get_DocumentElement();

 $root."system.net".mailSettings.smtp.network.host = $mailHost
 $root."system.net".mailSettings.smtp.network.userName = $mailUsername
 $root."system.net".mailSettings.smtp.network.password = $mailPassword
 $root."system.net".mailSettings.smtp.network.port = $mailPort
 $root."system.net".mailSettings.smtp.network.enableSsl = $mailEnableSSL

 # Save it
 $xml.Save($webConfigPath)
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23957949

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档