使用 PowerShell 删除虚拟网络网关(经典)Delete a virtual network gateway using PowerShell (classic)

本文可帮助在经典部署模型中使用 PowerShell 删除 VPN 网关。This article helps you delete a VPN gateway in the classic deployment model by using PowerShell. 删除虚拟网络网关后,修改网络配置文件以删除不再使用的元素。After the virtual network gateway has been deleted, modify the network configuration file to remove elements that you are no longer using.

步骤 1:连接到 AzureStep 1: Connect to Azure

1.安装最新的 PowerShell cmdlet。1. Install the latest PowerShell cmdlets.

使用经典部署模型时,必须在本地计算机上安装最新版本的 Azure 服务管理 (SM) PowerShell cmdlet。When working with the classic deployment model, you must install the latest version of the Azure Service Management (SM) PowerShell cmdlets locally on your computer. 这些 cmdlet 不同于 AzureRM 或 Az cmdlet。These cmdlets are different from the AzureRM or Az cmdlets. 若要安装 SM cmdlet,请参阅安装服务管理 cmdletTo install the SM cmdlets, see Install Service Management cmdlets. 有关一般 Azure PowerShell 的详细信息,请参阅 Azure PowerShell 文档For more information about Azure PowerShell in general, see the Azure PowerShell documentation.

2.连接到 Azure 帐户。2. Connect to your Azure account.

使用提升的权限打开 PowerShell 控制台,并连接到帐户。Open your PowerShell console with elevated rights and connect to your account. 使用下面的示例来帮助连接:Use the following example to help you connect:

  1. 使用提升的权限打开 PowerShell 控制台。Open your PowerShell console with elevated rights. 若要切换到服务管理,请使用以下命令:To switch to service management, use this command:

    azure config mode asm
    
  2. 连接到帐户。Connect to your account. 使用下面的示例来帮助连接:Use the following example to help you connect:

    Add-AzureAccount -Environment AzureChinaCloud
    

步骤 2:导出并查看网络配置文件Step 2: Export and view the network configuration file

在计算机上创建一个目录,并将网络配置文件导出到该目录。Create a directory on your computer and then export the network configuration file to the directory. 使用此文件查看当前配置信息并修改网络配置。You use this file to both view the current configuration information, and also to modify the network configuration.

本例中,网络配置文件导出到 C:\AzureNet。In this example, the network configuration file is exported to C:\AzureNet.

Get-AzureVNetConfig -ExportToFile C:\AzureNet\NetworkConfig.xml

使用文本编辑器打开文件,并查看经典 VNet 的名称。Open the file with a text editor and view the name for your classic VNet. 在 Azure 门户中创建 VNet 时,Azure 使用的全名在门户中不可见。When you create a VNet in the Azure portal, the full name that Azure uses is not visible in the portal. 例如,在 Azure 门户中命名为“ClassicVNet1”的 VNet 可能在网络配置文件中具有更长的名称。For example, a VNet that appears to be named 'ClassicVNet1' in the Azure portal, may have a much longer name in the network configuration file. 名称的外观可能如下:“Group ClassicRG1 ClassicVNet1”。The name might look something like: 'Group ClassicRG1 ClassicVNet1'. 虚拟网络名称以“VirtualNetworkSite name =” 的形式列出。Virtual network names are listed as 'VirtualNetworkSite name ='. 运行 PowerShell cmdlet 时,请使用网络配置文件中的名称。Use the names in the network configuration file when running your PowerShell cmdlets.

步骤 3:删除虚拟网络网关Step 3: Delete the virtual network gateway

删除虚拟网络网关时,通过该网关的所有 VNet 连接都会断开。When you delete a virtual network gateway, all connections to the VNet through the gateway are disconnected. 如果 P2S 客户端连接到 VNet,它们会断开连接且不发出警告。If you have P2S clients connected to the VNet, they will be disconnected without warning.

此示例删除虚拟网络网关。This example deletes the virtual network gateway. 确保使用网络配置文件中虚拟网络的全名。Make sure to use the full name of the virtual network from the network configuration file.

Remove-AzureVNetGateway -VNetName "Group ClassicRG1 ClassicVNet1"

如果成功,则返回显示:If successful, the return shows:

Status : Successful

步骤 4:修改网络配置文件Step 4: Modify the network configuration file

删除虚拟网络网关时,cmdlet 不会修改网络配置文件。When you delete a virtual network gateway, the cmdlet does not modify the network configuration file. 需修改文件才可删除不再使用的元素。You need to modify the file to remove the elements that are no longer being used. 以下部分可帮助你修改下载的网络配置文件。The following sections help you modify the network configuration file that you downloaded.

本地网络站点引用Local Network Site References

若要删除站点引用信息,请更改 ConnectionsToLocalNetwork/LocalNetworkSiteRef 的配置。To remove site reference information, make configuration changes to ConnectionsToLocalNetwork/LocalNetworkSiteRef. 删除本地站点引用会触发 Azure 删除隧道。Removing a local site reference triggers Azure to delete a tunnel. 根据已创建的配置,可能没有列出 LocalNetworkSiteRefDepending on the configuration that you created, you may not have a LocalNetworkSiteRef listed.

<Gateway>
   <ConnectionsToLocalNetwork>
     <LocalNetworkSiteRef name="D1BFC9CB_Site2">
       <Connection type="IPsec" />
     </LocalNetworkSiteRef>
   </ConnectionsToLocalNetwork>
 </Gateway>

示例:Example:

<Gateway>
   <ConnectionsToLocalNetwork>
   </ConnectionsToLocalNetwork>
 </Gateway>

本地网络站点Local Network Sites

删除不再使用的所有本地站点。Remove any local sites that you are no longer using. 根据已创建的配置,可能没有列出 LocalNetworkSiteDepending on the configuration you created, it is possible that you don't have a LocalNetworkSite listed.

<LocalNetworkSites>
  <LocalNetworkSite name="Site1">
    <AddressSpace>
      <AddressPrefix>192.168.0.0/16</AddressPrefix>
    </AddressSpace>
    <VPNGatewayAddress>5.4.3.2</VPNGatewayAddress>
  </LocalNetworkSite>
  <LocalNetworkSite name="Site3">
    <AddressSpace>
      <AddressPrefix>192.168.0.0/16</AddressPrefix>
    </AddressSpace>
    <VPNGatewayAddress>57.179.18.164</VPNGatewayAddress>
  </LocalNetworkSite>
 </LocalNetworkSites>

本例仅删除 Site3。In this example, we removed only Site3.

<LocalNetworkSites>
  <LocalNetworkSite name="Site1">
    <AddressSpace>
      <AddressPrefix>192.168.0.0/16</AddressPrefix>
    </AddressSpace>
    <VPNGatewayAddress>5.4.3.2</VPNGatewayAddress>
  </LocalNetworkSite>
 </LocalNetworkSites>

客户端地址池Client AddressPool

如果 P2S 连接到 VNet,将有一个 VPNClientAddressPoolIf you had a P2S connection to your VNet, you will have a VPNClientAddressPool. 删除与所删除的虚拟网络网关对应的客户地址池。Remove the client address pools that correspond to the virtual network gateway that you deleted.

<Gateway>
    <VPNClientAddressPool>
      <AddressPrefix>10.1.0.0/24</AddressPrefix>
    </VPNClientAddressPool>
  <ConnectionsToLocalNetwork />
 </Gateway>

示例:Example:

<Gateway>
  <ConnectionsToLocalNetwork />
 </Gateway>

GatewaySubnetGatewaySubnet

删除与 VNet 对应的 GatewaySubnetDelete the GatewaySubnet that corresponds to the VNet.

<Subnets>
   <Subnet name="FrontEnd">
     <AddressPrefix>10.11.0.0/24</AddressPrefix>
   </Subnet>
   <Subnet name="GatewaySubnet">
     <AddressPrefix>10.11.1.0/29</AddressPrefix>
   </Subnet>
 </Subnets>

示例:Example:

<Subnets>
   <Subnet name="FrontEnd">
     <AddressPrefix>10.11.0.0/24</AddressPrefix>
   </Subnet>
 </Subnets>

步骤 5:上传网络配置文件Step 5: Upload the network configuration file

保存所做的更改,并将网络配置文件上传到 Azure。Save your changes and upload the network configuration file to Azure. 确保根据环境需要更改文件路径。Make sure you change the file path as necessary for your environment.

Set-AzureVNetConfig -ConfigurationPath C:\AzureNet\NetworkConfig.xml

如果成功,则返回显示类似于下例的内容:If successful, the return shows something similar to this example:

OperationDescription        OperationId                      OperationStatus                                                
--------------------        -----------                      ---------------                                           
Set-AzureVNetConfig         e0ee6e66-9167-cfa7-a746-7casb9   Succeeded