如何使用 PowerShell 禁用 Azure VM 加速设置?

powershellmicrosoft technologiessoftware & coding更新于 2026/2/12 21:52:17

要使用 PowerShell 禁用 Azure VM 加速设置,我们需要禁用连接到 VM 的 NIC 上的 EnableAcceleratedNetworking 属性。

$vm = Get-AzVM -Name TestVM
$nicname = (($vm.NetworkProfile.NetworkInterfaces.id).Split('/'))[-1]
$nicsetting = Get-AzNetworkInterface -ResourceGroupName $vm.ResourceGroupName -
Name $nicname
$nicsetting.EnableAcceleratedNetworking = $false

在上面的示例中,我们在 Azure VM "TestVM"上设置了 AN 设置。要在特定订阅上设置 AN 设置,请使用以下命令。使用 Set-AzContext 命令确保您已连接到正确的订阅。

Get-AzVM | Select Name, ResourceGroupName,`
   @{N='Accelerated Netoworking'; E={
      $nic = (($_.NetworkProfile.NetworkInterfaces.id).Split('/'))[-1]
      $nicsetting = Get-AzNetworkInterface -
      ResourceGroupName $_.ResourceGroupName -Name $nic
      $nicsetting.EnableAcceleratedNetworking = $true
      if($nicsetting.EnableAcceleratedNetworking){"Enabled"}
      else{"Disabled"}
   }}

要设置特定资源组的虚拟机上的加速网络 (AN) 设置,请使用 Get-AzVM - ResourceGroupName ‘ResourceGroup’ 而不是上述代码中的 Get-AzVM。


相关文章