1

我无法使用 powershell cmdlet 连接到 VPN。我使用构建代理中的“rasdial”连接到 vpn,以便我们可以触发自动化测试。整个过程是自动化的。

早期相同的 rasdial 命令 -Rasdial "VPNName"与 vpn 的经典模型 (ASM) 完美配合。但是,在我迁移到 ARM 之后,我遇到了这个问题。然而,通过 UI,即单击按钮连接到 vpn 工作正常,但我们需要通过脚本连接。

我收到一条消息-

本系统不支持该功能。

注意:我正在关注这篇文章- https://dzone.com/articles/deconstructing-azure-point

相同的解决方法在 ASM 中有效,但在 ARM 中无效。什么可以是另一种解决方法或解决方法?

我正在使用下面的脚本来创建和下载 VPN 包。我不确定我的脚本中是否遗漏了导致此问题的某些内容-

$VNetName  = "MYVPN"
$SubName = "Subnet-1"
$GWSubName = "GatewaySubnet"
$VNetPrefix1 = "15.3.0.0/16"
$SubPrefix = "15.3.1.0/24"
$GWSubPrefix = "15.3.200.0/26"
$VPNClientAddressPool = "158.17.201.0/24"
$RG = "VMsRG"
$Location = "West Europe"
$DNS = "15.3.0.0"
$GWName = "GateWay"
$GWIPName = "GateWayIP"
$GWIPconfName = "GateWayIPConfig"
$P2SRootCertName = "XXXXX.cer"
$DeployUserName = "atf@hotmail.com"
$DeployUserPassword = "XXXXX" 

$Azurepwd = ConvertTo-SecureString $DeployUserPassword -AsPlainText -Force
$AzureCredential = new-object -typename System.Management.Automation.PSCredential -argumentlist $DeployUserName, $Azurepwd 
Add-AzureRmAccount -credential $AzureCredential -SubscriptionName Development

New-AzureRmResourceGroup -Name $RG -Location $Location
$fesub = New-AzureRmVirtualNetworkSubnetConfig -Name $SubName -AddressPrefix $SubPrefix
$gwsub = New-AzureRmVirtualNetworkSubnetConfig -Name $GWSubName -AddressPrefix $GWSubPrefix
New-AzureRmVirtualNetwork -Name $VNetName -ResourceGroupName $RG -Location $Location -AddressPrefix $VNetPrefix1 -Subnet $fesub, $gwsub -DnsServer $DNS

$vnet = Get-AzureRmVirtualNetwork -Name $VNetName -ResourceGroupName $RG
$subnet = Get-AzureRmVirtualNetworkSubnetConfig -Name "GatewaySubnet" -VirtualNetwork $vnet

$pip = New-AzureRmPublicIpAddress -Name $GWIPName -ResourceGroupName $RG -Location $Location -AllocationMethod dynamic

$ipconf = New-AzureRmVirtualNetworkGatewayIpConfig -Name $GWIPconfName -Subnet $subnet -PublicIpAddress $pip

$MyP2SRootCertPubKeyBase64 = "XXXXX"
$p2srootcert = New-AzureRmVpnClientRootCertificate -Name "P2SVNETRootCertName" -PublicCertData $MyP2SRootCertPubKeyBase64
New-AzureRmVirtualNetworkGateway -Name $GWName -ResourceGroupName $RG -Location $Location -IpConfigurations $ipconf -GatewayType Vpn -VpnType RouteBased -EnableBgp $false -GatewaySku Standard -VpnClientAddressPool $VPNClientAddressPool -VpnClientRootCertificates $p2srootcert
Get-AzureRmVpnClientPackage -ResourceGroupName $RG -VirtualNetworkGatewayName $GWName -ProcessorArchitecture Amd64

因为我能够使用 GUI 进行连接。我希望脚本正在做它的工作。

4

2 回答 2

2

4 个月后,我收到了 MS 的回复(因为我提出了同样的问题)。他们告诉 Rasdial,到目前为止,Azure VPN 客户端包还不支持。此外,即使在解构-the-azure-point-to-site-vpn 之后也缺少添加路由,应通过显式添加路由来加以注意。

因此,作为一种解决方法,我执行了博客中提供的步骤 - http://www.diaryofaninja.com/blog/2013/11/27/deconstructing-the-azure-point-to-site-vpn-for-command-line -用法

然而,添加路线的最后一部分有点复杂。因此,为了添加路线,我创建了自己的 PS 脚本-

$Subnet                  = @("10.0.1.0", "10.0.2.0","10.0.3.0")
$VPNClientAddressPool    = "x.x.x"  
$Mask                    = "255.255.0.0"
$azureIpAddress          = ""
$VPNCmd                  = "MYVPNName"

这里 xxx 是可以在 VPN 的“GateWay - 点到站点配置”中找到的 3 个八位字节-

在此处输入图像描述

    $routeExists = route print | findstr $VPNClientAddressPool
    if($routeExists) 
    {         
       route delete $Subnet          
    }

    rasdial $VPNCmd > $null
    $azureIPAddress = ipconfig | findstr $VPNClientAddressPool
    if($azureIPAddress -ne $null)
    {   
        $azureIpAddress = $azureIpAddress.Split(": ")
        $azureIpAddress = $azureIpAddress[$azureIpAddress.Length-1]
        $azureIpAddress = $azureIpAddress.Trim()
        route add $Subnet MASK $Mask $azureIPAddress    
    }   

这解决了我的目的。基本上你只需要处理路由添加部分。

于 2017-01-05T11:30:55.603 回答
0

您的 PowerShell 脚本似乎很好(我没有尝试登录和资源组部分,但其他一切都可以从 $fesub 开始。)除了底部的第三行。您当前作为“P2SVNETRootCertName”的 -Name 标签需要与您的 $P2SRootCertName 相同。有关详细信息,请参阅 Azure 文档:https ://azure.microsoft.com/en-us/documentation/articles/vpn-gateway-howto-point-to-site-rm-ps/

至于 Rasdial,另一个 StackOverflow 帖子已经回答了这个问题:Azure Virtual Network Point-to-Site (ex. Azure Connect) autoconnect

-布里奇特 [MSFT]

于 2016-10-07T23:49:48.177 回答