I am attempting to edit my WebApp's Web.config using the Kudu WebApp API and an Azure Automation Runbook.
Logging into the WebApp via the Kudu interface and executing the code in the PowerShell debugger removes the XML node as expected:
$username = "`$myusername"
$password = "123456"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))
$ProgressPreference="SilentlyContinue"
$apiUrl = "https://mysite.scm.azurewebsites.net/api/command"
$pscommand = $webConfigPath = "D:\home\site\wwwroot\Web.config"
[xml] $webConfigXML = Get-Content $webConfigPath
#remove the following handler in the <httpHanderls> section in the web.config
$targetName = "Sitecore.FeedRequestHandler"
$nodePath = "configuration/system.webServer/handlers/add[@name='{0}']" -f $targetName
$node = $webConfigXML.SelectSingleNode($nodePath)
if($node -ne $null)
{
$webConfigXML.configuration.'system.webServer'.handlers.RemoveChild($node)
}
$webConfigXML.Save($webConfigPath)
$commandBody = @{
command = "powershell -command `"$pscommand`""
}
Invoke-RestMethod -Uri $apiUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method POST -ContentType "application/json" -Body (ConvertTo-Json $commandBody)
However, if I try to run this via PowerShell ISE or an Azure Automation Runbook, it produces the following errors:
Program 'Web.config' failed to run: Access is deniedAt line:1 char:1..
Get-Content : Cannot find path 'D:\home\site\wwwroot\Web.config' because it does not exist.
Any ideas on how I can edit the XML of the Web.config via an Azure Automation Runbook?