Skip to content

Instantly share code, notes, and snippets.

@chgeuer
Created April 15, 2013 08:12
Show Gist options
  • Select an option

  • Save chgeuer/5386610 to your computer and use it in GitHub Desktop.

Select an option

Save chgeuer/5386610 to your computer and use it in GitHub Desktop.
Tweak an XML Document with Powershell and LINQ
[Reflection.Assembly]::LoadWithPartialName("System.Xml.Linq")
$roleroot = Get-Content Env:\RoleRoot
$pathToPhp = "$roleroot\approot\php\php-cgi.exe";
$content = [System.IO.File]::ReadAllText("C:\PHP\web.config");
$doc = [System.Xml.Linq.XDocument]::Parse($content);
$elements = $doc.Element("configuration").Element("system.webServer").Element("handlers").Elements("add");
$elementslist = [System.Linq.Enumerable]::ToList($elements);
foreach ($e in $elementslist)
{
$e.Attribute("scriptProcessor").SetValue($pathToPhp)
}
[System.IO.File]::WriteAllText("C:\PHP\web.config", $doc.ToString());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment