-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathVM-anFeature.ps1
28 lines (27 loc) · 990 Bytes
/
VM-anFeature.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#
# Script by Anderson Patricio (AP6) - [email protected]
# Source: github.com/andersonpatricio
#
Param(
[string]$VMName
)
#retrieving Resource Group and Virtual vNIC
$vm = Get-AzVM | Where-Object { $_.Name -eq $vmName }
If (!$vm){
Write-Host -Foregroundcolor 'Yellow' "The VM $vmName cannot be found in your current subscription."
break
}Else{
$rg = (Get-AzVM | Where-Object { $_.Name -eq $vmName } ).ResourceGroupName
Write-Host "Stopping the VM $vmName..."
Write-Host
Stop-AzVM -Name $vmName -ResourceGroup $rg -Force
Start-Sleep -Seconds 180
$vtempNIC = Get-AzVM | Where-Object { $_.Name -eq $vmName }
$vtempNIC = $vtempNIC.NetworkProfile.NetworkInterfaces.Id.Split("/")
$vNIC = Get-AzNetworkInterface -Name $vTempNIC[-1] -ResourceGroupName $rg
$vNIC.EnableAcceleratedNetworking = $true
$vNIC | Set-AzNetworkInterface
Write-Host
Write-Host "Starting the VM $vmName ..."
Start-AzVM -ResourceGroup $rg -Name $vmName
}