有没有人知道如何使用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
}
}
答案 0 :(得分:2)
您需要将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