Powershell azure - 将 csv 文件导入 appsettings

Powershell azure - Importing csv file into appsettings

有谁知道如何使用 powershell 将 csv 文件导入到 Azure 应用程序设置中?

这是我目前拥有的但不起作用。

Function Import-AppSettings 
{
Step-TimeBlock {  

    $csv = "C:\appsettings.csv"
    $appSettingsList = Import-Csv $csv -Encoding UTF8 -Delimiter '|'

    $appSettingsHash = @{}
    Write-Host "current app settings" -foreground yellow;
    ForEach ($kvp in $appSettingsList) {
        $appSettingsHash[$kvp.Name] = $kvp.Value
        write-host $kvp.Name ": " $kvp.Value -foreground green;
    }

    Set-AzureRMWebApp -ResourceGroupName myresourcegroup -Name mywebapp -AppSettings $appSettingsHash
}
}

您需要 Set-AzureRmWebApp 移动到 Foreach 循环。

以下脚本适合我。

$csv = "d:\webapp.csv"
$appSettingsList = Import-Csv $csv 

$appSettingsHash = @{}
Write-Host "current app settings" -foreground yellow;
ForEach ($kvp in $appSettingsList) {
    $appSettingsHash[$kvp.Name] = $kvp.Value
    write-host $kvp.Name ": " $kvp.Value -foreground green;
    Set-AzureRMWebApp -ResourceGroupName shuiweb -Name shuiweb -AppSettings $appSettingsHash
}

我的 csv 文件如下:

Name,Value
shuivnet1,shuitest1
shuivnet3,shuitest2

注意:如果我使用 -Encoding UTF8 -Delimiter '|',您的脚本将不起作用。为了测试,我建议你可以得到一个 $appSettingHash 并检查你的哈希值。如下所示:

$appSettingsHash[$appSettingsList.Name[0]]=$appSettingsList.Value[0] 
$appSettingsHash

值应该如下所示:

PS C:\Users\v-shshui> $appSettingsHash

Name                           Value
----                           -----
shuivnet1                      shuitest1