Powershell azure-将csv文件导入appsettings
有人知道如何使用powershell将csv文件导入Azure应用程序设置吗 这是我目前拥有的,但不起作用Powershell azure-将csv文件导入appsettings,powershell,azure,import,appsettings,Powershell,Azure,Import,Appsettings,有人知道如何使用powershell将csv文件导入Azure应用程序设置吗 这是我目前拥有的,但不起作用 Function Import-AppSettings { Step-TimeBlock { $csv = "C:\appsettings.csv" $appSettingsList = Import-Csv $csv -Encoding UTF8 -Delimiter '|' $appSettingsHash = @{} Write-Host "
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
}
}
您需要移动
设置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
$appSettingsHash[$appSettingsList.Name[0]]=$appSettingsList.Value[0]
$appSettingsHash
PS C:\Users\v-shshui> $appSettingsHash
Name Value
---- -----
shuivnet1 shuitest1
注意:如果我使用-Encoding UTF8-分隔符“|”
,您的脚本将无法工作。对于测试,我建议您可以获取一个$appSettingHash
并检查您的哈希值。如下图所示:
Name,Value
shuivnet1,shuitest1
shuivnet3,shuitest2
$appSettingsHash[$appSettingsList.Name[0]]=$appSettingsList.Value[0]
$appSettingsHash
PS C:\Users\v-shshui> $appSettingsHash
Name Value
---- -----
shuivnet1 shuitest1
该值应如下所示:
Name,Value
shuivnet1,shuitest1
shuivnet3,shuitest2
$appSettingsHash[$appSettingsList.Name[0]]=$appSettingsList.Value[0]
$appSettingsHash
PS C:\Users\v-shshui> $appSettingsHash
Name Value
---- -----
shuivnet1 shuitest1
您需要在Foreach循环中添加
Set AzureRmWebApp
。非常感谢。这对我来说确实有效。杰出的stuff@shui-因为某种原因,我运行了你的脚本,我所有现有的应用程序设置都被删除了,你有什么想法?