WhiskerBiscuit
WhiskerBiscuit

Reputation: 5157

How can you delete files from an Azure WebApp using powershell?

Suppose I want to delete all files matching *.config.default from an Azure WebApp. How can I do this with PowerShell? If I had a directory on my local machine I can do this with:

get-childitem -Path . -Filter *.config.default -Recurse | remove-item

I can currently get the webApp using the following, but I don't think this will allow me to delete any files

$webapp = Get-AzureRMWebApp -ResourceGroupName $ResourceGroupName -Name $WebSiteName -ea SilentlyContinue

I know I can use the KUDU console which will allow me access to PS D:\home\site\wwwroot> and then I can use Powershell commands from there, but I need to be able to do this without using the console.

Upvotes: 2

Views: 3465

Answers (1)

evilSnobu
evilSnobu

Reputation: 26314

Call the Kudu VFS APIs.

DELETE /api/vfs/{path} -- Delete the file at path.

DELETE https://{site}.scm.azurewebsites.net/api/vfs/wwwroot/some.config.default

If you really want that wildcard, call the command API instead: https://github.com/projectkudu/kudu/wiki/REST-API#command

Of course you should never do this for an app that matters, instead you should make changes to source control and redeploy.

Upvotes: 4

Related Questions