0

我正在尝试通过 Powershell 启用/禁用流量管理器端点以帮助进行环境配置。在我们的一个资源组上,cmdlet 运行良好,但我们在其他资源组中看到了一些奇怪的行为。

在一种情况下,TrafficManagerEndpoint直接将 a 传递给 cmdlet(通过管道或参数)会返回 400 并吐出完整的 HTML:

> $tm = Get-AzureRmTrafficManagerProfile -Name <tm-name> -ResourceGroupname <rg-name>
> $tm.Endpoints[0] | Disable-AzureRmTrafficManagerEndpoint

Confirm
Are you sure you want to disable endpoint '<tm-endpoint-name>' of Profile '<tm-name>'?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): y
Disable-AzureRmTrafficManagerEndpoint : <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>Request Error</title>
    <style>BODY { color: #000000; background-color: white; font-family: Verdana; margin-left: 0px; margin-top: 0px; } #content { margin-left: 30px; font-size: .70em; padding-bottom: 2em; } A:link { color: #336699;
font-weight: bold; text-decoration: underline; } A:visited { color: #6699cc; font-weight: bold; text-decoration: underline; } A:active { color: #336699; font-weight: bold; text-decoration: underline; } .heading1 {
background-color: #003366; border-bottom: #336699 6px solid; color: #ffffff; font-family: Tahoma; font-size: 26px; font-weight: normal;margin: 0em 0em 10px -20px; padding-bottom: 8px; padding-left:
30px;padding-top: 16px;} pre { font-size:small; background-color: #e5e5cc; padding: 5px; font-family: Courier New; margin-top: 0px; border: 1px #f0f0e0 solid; white-space: pre-wrap; white-space: -pre-wrap;
word-wrap: break-word; } table { border-collapse: collapse; border-spacing: 0px; font-family: Verdana;} table th { border-right: 2px white solid; border-bottom: 2px white solid; font-weight: bold;
background-color: #cecf9c;} table td { border-right: 2px white solid; border-bottom: 2px white solid; background-color: #e5e5cc;}</style>
  </head>
  <body>
    <div id="content">
      <p class="heading1">Request Error</p>
      <p>The server encountered an error processing the request. See server logs for more details.</p>
    </div>
  </body>
</html>
At line:1 char:20
+ $tm.Endpoints[0] | Disable-AzureRmTrafficManagerEndpoint
+                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Disable-AzureRmTrafficManagerEndpoint], CloudException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.TrafficManager.DisableAzureTrafficManagerEndpoint

使用Enable-AzureRmTrafficManagerEndpointand时也会发生同样的情况Set-AzureRmTrafficManagerEndpoint

使用资源名称调用 cmdlet 时,Diable-AzureRmTrafficManagerEndpoint效果很好,但是当Enable-AzureRmTrafficManagerEndpoint以这种方式调用时,我得到NullReferenceException

> Disable-AzureRmTrafficManagerEndpoint -Name <tm-endpoint-name> -ProfileName <tm-name> -ResourceGroupName <rg-name> -Type AzureEndpoints

Confirm
Are you sure you want to disable endpoint '<tm-endpoint-name>' of Profile '<tm-name>'?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): y
False
> Enable-AzureRmTrafficManagerEndpoint -Name <tm-endpoint-name> -ProfileName <tm-name> -ResourceGroup <rg-name> -Type AzureEndpoints
Enable-AzureRmTrafficManagerEndpoint : Object reference not set to an instance of an object.
At line:1 char:1
+ Enable-AzureRmTrafficManagerEndpoint -Name $tmEndpoint.Name -ProfileN ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Enable-AzureRmTrafficManagerEndpoint], NullReferenceException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.TrafficManager.EnableAzureTrafficManagerEndpoint

我确定这些名字是正确的。对此有任何见解吗?我的 AzureRM.TrafficManager 模块似乎与 Azure 不同步,但我尝试安装 Web 平台安装程序中可用的任何内容,但没有得到任何结果。(模块版本为 3.0.0)。谢谢!

编辑:我忘记了更多信息:

.NET Azure SDK 版本:2.9

电源外壳版本:

Name                           Value
----                           -----
PSVersion                      5.1.14393.953
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.953
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
4

1 回答 1

1

根据您的描述,我们可以使用这样的 Azure PowerShell 脚本来启用或禁用流量管理器端点。

使用此脚本禁用Azure 流量管理器终结点:

PS C:\Users> $endpoint1 = Get-AzureRmTrafficManagerEndpoint -Name web1 -Type AzureEndpoints -ProfileName jasontm -ResourceGroupName jason
PS C:\Users> $endpoint1.EndpointStatus
Enabled
PS C:\Users> $endpoint1.EndpointStatus = "Disabled"
PS C:\Users> $endpoint1.EndpointStatus
Disabled
PS C:\Users> $endpoint1 | Set-AzureRmTrafficManagerEndpoint


Id                    : /subscriptions/5384xxxx-xxxx-xxxx-xxxx-xxxxe29axxxx/resourceGroups/jason/providers/Microsoft.Network/trafficManagerProfiles/jasontm/azureEndpoints/web1
Name                  : web1
ProfileName           : jasontm
ResourceGroupName     : jason
Type                  : AzureEndpoints
TargetResourceId      : /subscriptions/5384xxxx-xxxx-xxx-xxxx-xxxxe29axxxx/resourceGroups/jason/providers/Microsoft.Network/publicIPAddresses/jasonweb1-ip
Target                : jasonweb1.eastus.cloudapp.azure.com
EndpointStatus        : Disabled
Weight                : 1
Priority              : 1
Location              : East US
EndpointMonitorStatus : Disabled
MinChildEndpoints     :

使用此脚本启用Azure 流量管理器终结点:

PS C:\Users> $endpoint1 = Get-AzureRmTrafficManagerEndpoint -Name web1 -Type AzureEndpoints -ProfileName jasontm -ResourceGroupName jason
PS C:\Users> $endpoint1.EndpointStatus
Disabled
PS C:\Users> $endpoint1.EndpointStatus = "Enabled"
PS C:\Users> $endpoint1.EndpointStatus
Enabled
PS C:\Users> $endpoint1 | Set-AzureRmTrafficManagerEndpoint


Id                    : /subscriptions/5384xxxx-xxxx-xxxx-xxxx-xxxxe29axxxx/resourceGroups/jason/providers/Microsoft.Network/trafficManagerProfiles/jasontm/azureEndpoints/web1
Name                  : web1
ProfileName           : jasontm
ResourceGroupName     : jason
Type                  : AzureEndpoints
TargetResourceId      : /subscriptions/5384xxxx-xxxx-xxxx-xxxx-xxxxe29axxxx/resourceGroups/jason/providers/Microsoft.Network/publicIPAddresses/jasonweb1-ip
Target                : jasonweb1.eastus.cloudapp.azure.com
EndpointStatus        : Enabled
Weight                : 1
Priority              : 1
Location              : East US
EndpointMonitorStatus : CheckingEndpoint
MinChildEndpoints     :

顺便说一句,我使用的是 Azure PowerShell 3.7.0 版:

PS C:\Users> Get-Module -ListAvailable -Name Azure -Refresh


    Directory: C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement


ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   3.7.0      Azure                               {Get-AzureAutomationCertificate, Get-AzureAutomationConnection, New-AzureAutomationConnection, Remove-AzureAutomationConnection...}
于 2017-05-16T02:46:38.820 回答