pldiguanaman
pldiguanaman

Reputation: 125

How can I retrieve files within a repo in Azure within a Powershell script?

I need to (within a Powershell script) determine all the possible controller file names within a repository. This is for a test that will hit every controller and verify it is functioning and not missing from the startup file. (MVC app)

Since all the files are DLLs I cannot simply ask for the files in the folder nor do I want to hard code the names. How can I get a listing of files within a certain folder in order call each one to test within a powershell script?

Perhaps a better way to ask this is: How can I list files within a folder that is inside a repo? (using a Powershell script)

Upvotes: 0

Views: 1236

Answers (1)

George Chen
George Chen

Reputation: 14334

You could refer to this doc:Interacting with Azure Web Apps Virtual File System using PowerShell and the Kudu API. It uses the VFS API in the wiki doc. And there is a api to list files at directory specified by path.

GET /api/vfs/{path}/
Lists files at directory specified by path.

And in the previous doc, under the title Downloading a File from an App Service, there is a scripts to download the files. I use the path without $kuduPath to list files. And you need to Getting the Kudu REST API Authorisation header via PowerShell. And then the scripts would be like this.

$kuduApiUrl="https://<webname>.scm.azurewebsites.net/api/vfs/site/wwwroot/"
 Invoke-RestMethod -Uri $kuduApiUrl `
 -Headers @{"Authorization"=$kuduApiAuthorisationToken;"If-Match"="*"} `
 -Method GET `
 -OutFile $localPath `
 -ContentType "multipart/form-data"

And here is the result pic.It will list all files and the folders.

enter image description here

hope this could help you, if you still have other questions,please let me know.

Upvotes: 1

Related Questions