无法使用PowerShell以编程方式将多个自定义主机名添加到Azure Webapp [英] Not able to programatically add multiple custom hostnames to Azure webapp using PowerShell

查看:113
本文介绍了无法使用PowerShell以编程方式将多个自定义主机名添加到Azure Webapp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过代码向Web应用程序添加多个自定义域时出现问题.我们正在使用Powershell来自动将客户添加到多租户平台,因此需要能够添加多个自定义域.

Having issues adding multiple custom domains to webapps via code. We are using powershell to automate adding customers to a multitenant platform so need to be able to add mutliple custom domains.

我跑步时
Set-AzureRmWebApp-名称$ azwebapp -ResourceGroupName $ RGName -HostNames @("custom1.domain.com","custom2.domain.com")
可以.

When I run
Set-AzureRmWebApp -Name $azwebapp -ResourceGroupName $RGName -HostNames @("custom1.domain.com","custom2.domain.com")
it works.

但是,由于该过程将是自动化的,因此我需要能够首先检查其中的内容,然后简单地添加到其中.为此,我首先使用以下方法收集自定义域:
$ webhosts =(Get-AzureRmWebApp -ResourceGroupName $ RGName -Name $ azwebapp).主机名
然后,我将新域添加到其中
$ webhosts.Add("custom3.domain.com")

However, as the process will be automated I need to be able to inspect what is there first, and simply add to it. I do this by collecting the custom domains first using:
$webhosts = (Get-AzureRmWebApp -ResourceGroupName $RGName -Name $azwebapp).Hostnames
I then add my new domain to it
$webhosts.Add("custom3.domain.com")

但是当我将其传递回Set-AzureRmWebApp命令时,它会失败:

But when I pass that back to the Set-AzureRmWebApp command it fails:

Set-AzureRmWebApp-名称$ azwebapp -ResourceGroupName $ RGName-主机名$ webhosts

Set-AzureRmWebApp -Name $azwebapp -ResourceGroupName $RGName -HostNames $webhosts

我也尝试过将其作为数组传递,也不起作用.

I've also tried passing it as an array, also does not work.

Set-AzureRmWebApp-名称$ azwebapp -ResourceGroupName $ RGName-主机名@($ addweb)

Set-AzureRmWebApp -Name $azwebapp -ResourceGroupName $RGName -HostNames @($addweb)

在查看$ webhosts时,我注意到它没有列出引号,因此我操纵了字符串以添加引号:

Looking at $webhosts I notice that it does not list the quotes, so I manipulate the string to add them:

$ addweb =新对象System.Collections.Generic.List [string]
$ webhosts =(Get-AzureRmWebApp -ResourceGroupName $ RGName -Name $ azwebapp).主机名
$ w = $ null
$ wo = $ null
foreach($ webhosts中的$ w){
$ w = $ w.insert(0,''''')
$ w + ='"'
$ addweb.add($ w)
$ wo + ="$ w`n"
}

$addweb = New-Object System.Collections.Generic.List[string]
$webhosts = (Get-AzureRmWebApp -ResourceGroupName $RGName -Name $azwebapp).Hostnames
$w = $null
$wo = $null
foreach ($w in $webhosts){
$w = $w.insert(0,'"')
$w += '"'
$addweb.add($w)
$wo += "$w `n"
}

然后我添加我的新域
$ webapp ='" custom1.domain.com"'
$ webapp2 ='" custom2.domain.com"'
$ addweb.Add($ webapp)

I then add my new domains
$webapp = '"custom1.domain.com"'
$webapp2 = '"custom2.domain.com"'
$addweb.Add($webapp)

$ addweb.Add($ webapp2)

$addweb.Add($webapp2)

然后清理以删除多余的逗号和换行符
$ weburls =($ addweb -join``,'').TrimEnd('','')

Then clean up to remove extra commas and line breaks
$weburls = ($addweb -join ",").TrimEnd(",")

然后将其传递给函数
Set-AzureRmWebApp-名称$ azwebapp -ResourceGroupName $ RGName -HostNames $ weburls

Then pass this to the function
Set-AzureRmWebApp -Name $azwebapp -ResourceGroupName $RGName -HostNames $weburls

但是失败了.我已经尝试了许多不同的方法,但都没有成功的方法(除非您手动指定-Hostnames @("hostname1","hostname2").)为什么这样做?有没有解决的办法?

But it fails. I've tried many different approaches with none able to succeed (unless you manually specify -Hostnames @("hostname1","hostname2"). Why is this? is there a way around this?

警告:15:21:58-无法设置自定义主机名"webapptest344354.azurewebsites.net","custom1.domain.com","custom2.domain.com"".详细信息:Microsoft.Rest.Azure.CloudException:主机名"webapptest344354.azurewebsites.net","custom1.domain.com","custom2.domain.com"; 无效.
在Microsoft.Azure.Management.WebSites.WebAppsOperations中.< CreateOrUpdateHostNameBindingWithHttpMessagesAsync> d__73.MoveNext()
---从之前引发异常的位置开始的堆栈跟踪---
在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)上
在Microsoft.Azure.Management.WebSites.WebAppsOperationsExtensions中.< CreateOrUpdateHostNameBindingAsync> d__137.MoveNext()
---从之前引发异常的位置开始的堆栈跟踪---
在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)上
在Microsoft.Azure.Commands.WebApps.Utilities.WebsitesClient.AddCustomHostNames(字符串resourceGroupName,字符串位置,字符串webAppName,字符串[]主机名)
警告:15:21:59-无法删除自定义主机名'webapptest344354.azurewebsites.net'.详细信息:Microsoft.Rest.Azure.CloudException:该站点的主机名必须包括带有dns后缀'azurewebsi
的默认主机名. tes.net".当前指定的主机名是:无".
在Microsoft.Azure.Management.WebSites.WebAppsOperations中.< DeleteHostNameBindingWithHttpMessagesAsync> d__74.MoveNext()
---从之前引发异常的位置开始的堆栈跟踪---
在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)上
在Microsoft.Azure.Management.WebSites.WebAppsOperationsExtensions中.< DeleteHostNameBindingAsync> d__139.MoveNext()
---从之前引发异常的位置开始的堆栈跟踪---
在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)上
在Microsoft.Azure.Commands.WebApps.Utilities.WebsitesClient.AddCustomHostNames(字符串resourceGroupName,字符串位置,字符串webAppName,字符串[]主机名)

WARNING: 15:21:58 - Could not set custom hostname '"webapptest344354.azurewebsites.net","custom1.domain.com","custom2.domain.com"'. Details: Microsoft.Rest.Azure.CloudException: The host name "webapptest344354.azurewebsites.net","custom1.domain.com","custom2.domain.com" is invalid.
at Microsoft.Azure.Management.WebSites.WebAppsOperations.<CreateOrUpdateHostNameBindingWithHttpMessagesAsync>d__73.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Management.WebSites.WebAppsOperationsExtensions.<CreateOrUpdateHostNameBindingAsync>d__137.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Commands.WebApps.Utilities.WebsitesClient.AddCustomHostNames(String resourceGroupName, String location, String webAppName, String[] hostNames)
WARNING: 15:21:59 - Could not remove custom hostname 'webapptest344354.azurewebsites.net'. Details: Microsoft.Rest.Azure.CloudException: The host names for the site must include the default hostname with dns suffix 'azurewebsi
tes.net'. Currently specified hostnames are: 'None'.
at Microsoft.Azure.Management.WebSites.WebAppsOperations.<DeleteHostNameBindingWithHttpMessagesAsync>d__74.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Management.WebSites.WebAppsOperationsExtensions.<DeleteHostNameBindingAsync>d__139.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Commands.WebApps.Utilities.WebsitesClient.AddCustomHostNames(String resourceGroupName, String location, String webAppName, String[] hostNames)

注意:上面的域名出于明显的原因而被清除,并且我要添加的域也存在CNAME.

Note: domain names above is sanitised for obvious reasons, and CNAMEs exist for domains I am trying to add as well.

推荐答案

链接 .这可能会对您有所帮助.

You can find similar thread in this link. This might help you.

.

If this answer was helpful, click "Mark as Answer" or "Up-Vote". To provide additional feedback on your forum experience, click here.


这篇关于无法使用PowerShell以编程方式将多个自定义主机名添加到Azure Webapp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆