다음을 통해 공유


PowerShell script to save a list of folder and file contents & file sizes to a csv file in App Service

When you encounter an unexpected runtime symptom that occurs after you deploy to your site, there are situations where it makes sense to further isolate whether this is a runtime issue or a deployment issue. A deployment issue is an issue where the wrong files are deployed. A runtime issue is an issue where the expected files are deployed, but the application doesn't work as expected. For example, such situations might include ones where the (presumably) same deployment works on another site, or where the site doesn't render as expected, or where you get a consistent error doesn't seem to have any relation to the change that was made to the application, or a consistent runtime error in a new Kudu deployment on a new App Service that doesn't reproduce when deployed to a different environment (eg on-premises IIS).'

 

The simplest way to determine whether the correct files are deployed are to compare the contents of the App Service's wwwroot folder to the contents of a working site to see if they match.

 

Here is a PowerShell script that lists the contents of the wwwroot folder in App Service and saves this list to a csv file. It saves the list of contents to d:\home\site\temp\contents.csv . You can also use the script to list the contents of the local app (change the $siteFolder and $tempFolder values to point to appropriate locations on your local app's server). You can then use a content comparison tool (MS Word, for example) to compare the contents of the local app's folder and App Service folder.

You can use the App Service's PowerShell Kudu console to run the script in App Service, as well as to download the csv that gets generated:

https://<AppServiceName>.scm.azurewebsites.net/DebugConsole/?shell=powershell

 

<# folder to recursively list the contents of #>

$siteFolder="D:\home\site\wwwroot";

<# path to write the list of contents to #>

$tempFolder="d:\home\site\temp";

<# csv file to write the list of contents to #>

$csvFile="contents.csv";

<# Delimiter to use in the csv file #>

$delimiter= ',';

if (!(Test-Path $tempFolder -PathType Container)) {New-Item -ItemType Directory -Force -Path $tempFolder}get-childitem $siteFolder -rec  | select-object FullName, Length | export-csv -notypeinformation -delimiter $delimiter -path $tempFolder\$csvFile

 

Further information about investigating deployment versus runtime issues is posted here:

https://github.com/projectkudu/kudu/wiki/Deployment-vs-runtime-issues