Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PowerShell注释掉web.config上的appSettings_Powershell_Web Config - Fatal编程技术网

使用PowerShell注释掉web.config上的appSettings

使用PowerShell注释掉web.config上的appSettings,powershell,web-config,Powershell,Web Config,我想知道是否有人可以使用PowerShell对appSettings的本节进行评论。下面的示例代码:(只是一个示例,不是我的代码) 我想对这一部分进行评论: <add key="SCVMMServerName" value="VMM01" /> 结果如下: <configuration> <connectionStrings> <add name="TestDBEntities" connectionString="metad

我想知道是否有人可以使用PowerShell对appSettings的本节进行评论。下面的示例代码:(只是一个示例,不是我的代码)


我想对这一部分进行评论:

<add key="SCVMMServerName" value="VMM01" />

结果如下:

<configuration>
   <connectionStrings>
      <add name="TestDBEntities" connectionString="metadata=res://*/TestProject.csdl|res://*/TestProject.ssdl|res://*/TestProject.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=SQL01;initial catalog=TestDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
   </connectionStrings>
   <appSettings>
      <!--<add key="SCVMMServerName" value="VMM01" />-->
      <add key="SCVMMServerPort" value="8100" />
   </appSettings>
</configuration>
$XmlDocument = [xml](Get-Content -Path "U:\test.xml")
$node = $XmlDocument.SelectNodes('//SomeNode') | Where-Object{$_.Key -eq "test2"}
$node.ParentNode.InnerXml = $node.ParentNode.InnerXml.Replace($node.OuterXml, $node.OuterXml.Insert(0, "<!--").Insert($node.OuterXml.Length+4, "-->"))
$XmlDocument.Save("U:\test.xml")


希望你们这些家伙(特别是外面的PowerShell书呆子)能帮我。非常感谢

试试这样的方法:

<configuration>
   <connectionStrings>
      <add name="TestDBEntities" connectionString="metadata=res://*/TestProject.csdl|res://*/TestProject.ssdl|res://*/TestProject.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=SQL01;initial catalog=TestDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
   </connectionStrings>
   <appSettings>
      <!--<add key="SCVMMServerName" value="VMM01" />-->
      <add key="SCVMMServerPort" value="8100" />
   </appSettings>
</configuration>
$XmlDocument = [xml](Get-Content -Path "U:\test.xml")
$node = $XmlDocument.SelectNodes('//SomeNode') | Where-Object{$_.Key -eq "test2"}
$node.ParentNode.InnerXml = $node.ParentNode.InnerXml.Replace($node.OuterXml, $node.OuterXml.Insert(0, "<!--").Insert($node.OuterXml.Length+4, "-->"))
$XmlDocument.Save("U:\test.xml")
$XmlDocument=[xml](获取内容-路径“U:\test.xml”)
$node=$XmlDocument.SelectNodes('//SomeNode')|其中的对象{$\ Key-eq“test2”}
$node.ParentNode.InnerXml=$node.ParentNode.InnerXml.Replace($node.OuterXml,$node.OuterXml.Insert(0“”))
$XmlDocument.Save(“U:\test.xml”)

在V3及更高版本中非常容易操作

(Get-Content c:\test.txt).replace('[Add value here]', 'New value') | Set-Content c:\test.txt

希望有帮助

这只能编辑“添加关键点”部分中的值。例如,在
中,使用此代码时,它只会将“VMM01”修改为其他值。我想做的是注释掉整个addkey部分。不,它对我来说很好。(获取内容C:\Users\RD\Desktop\test.config)。替换(“”),|设置内容C:\Users\RD\Desktop\test.config第三行是我要查找的内容。谢谢你的帮助。我让它工作在我的代码上。很高兴听到。当它对您有效时,请将其标记为答案。