2016-11-23 59 views
0

我有一个PowerShell脚本来设置应用程序配置设置,就像这样:登录-AzureRmAccount无人值守

Set-AzureRMWebApp -Name $SiteName -ResourceGroupName $ResourceGroupName -AppSettings $settings 

这个脚本会在Azure中,也通过他们的VS2015 IDE内开发VSTS发布,管理使用。

PS脚本有一个命令“Login-AzureRmAccount”,它将在其本地开发机器上显示一个弹出窗口,没关系。

但是这个脚本是利用PS的任务也被发布,管理,但踢了一个版本时,我得到一个错误: “显示模式对话框或形成当应用程序不UserInteractive模式下运行时不是有效的操作'

如何防止VSTS中的对话框? (请注意Set-AzureRMWebApp似乎工作正常,但只有防止对话导致任务错误)。

+1

请参阅'使用服务主体部分进行身份验证:https://blogs.endjin.com/2016/01/azure-resource-manager-authentication-from-a-powershell-script/。 HTH。 –

+0

如果您使用的是“Azure Powershell脚本”任务,则脚本运行时,该过程已经过身份验证。我想你只需要弄清楚如何跳过'Login-AzureRmAccount'。 –

回答

0

这是工作的修补程序:

if ([Environment]::UserInteractive -and 
     !([Environment]::GetCommandLineArgs() |? {$_ -ilike '-NonI*'})) 
{ 
    Login-AzureRmAccount 
} 
0

您需要对脚本的登录部分进行参数设置,以便它仅在未由开发人员运行时运行。当开发者运行它时,用一个开关调用它来说明。

然后,你可以这样做

$secret = yourServicePrincipalKey 
$azureApplicationId = yourServicePrincipalID 
if (!switch) 
{ 
$password = ConvertTo-SecureString -String $secret -AsPlainText -Force 
$creds = New-Object System.Management.Automation.PSCredential ($azureApplicationId, $password) 
$access = Login-AzureRmAccount -Credential $creds -ServicePrincipal -TenantId $tenantId 
} 

你可以看到,登录-AzureRmAccount有-servicePrincipal开关启用