Accelerated Networking enables single root I/O virtualization (SR-IOV) to a VM, greatly improving its networking performance. This high-performance path bypasses the host from the Datapath, reducing latency, jitter, and CPU utilization, to be used with the most demanding network workloads on supported VM types.
Prerequisite
Steps to Enable Accelerated Networking Manually:
Now, let’s imagine the same steps to be performed for 200 machines. Isn’t that time-consuming? Also, it might lead to some errors in the process of the task.
To resolve this issue, we can utilize PowerShell and Excel sheets.
#--------------------------Create/Get Excel File---------------------------
$file = "C:\Users\sourabh.majali\Downloads\ExcelSheet.xlsx"
$sheetName = "Sheet1"
$objExcel = New-Object -ComObject Excel.Application
$workbook = $objExcel.Workbooks.Open($file)
$sheet = $workbook.Worksheets.Item($sheetName)
$objExcel.Visible=$false
$rowMax = ($sheet.UsedRange.Rows).count
$rowcustname ,$colcustname = 1,1
$rowsubid ,$colsubid = 1,2
$rowtenantid ,$coltenantid = 1,3
This selects all the data in your Excel sheet and imports it into your PS script for further use.
The next series of commands is used to loop all the rows and columns of the Excel sheet to fetch the VM Name and their Resource Groups
for($i=1;$i -lt $rowMax;$i++)
{
$VMName=$sheet.Cells.Item($rowcustname+$i,$colcustname).text
$RG=$sheet.Cells.Item($rowcustname+$i,$colcustname+1).text
Write-Host "_________________________________________" -ForegroundColor Yellow
Write-Host "Checking for machine $VMName...." -ForegroundColor Green
$vm=Get-AzVM -Name $VMName -ResourceGroupName $RG
$status= (Get-AzVM -Name $vm.Name -ResourceGroupName $vm.ResourceGroupName - Status).Statuses[1].DisplayStatus
if($status -ne "VM deallocated")
{
Write-Host "VM was still running...Stop the machine and retry" -ForegroundColor Red
$sheet.Cells.Item($rowcustname+$i,$colcustname+3)= "VM was still running...Stop and retry"
}
else
{
Write-Host "$VMName is in Deallocated state...proceeding further..." -ForegroundColor White
$nics=$vm.NetworkProfile.NetworkInterfaces
foreach($nic in $nics)
{
Write-Host "Enabling Accelarated Networking on " $nic.Id
$GetNICDetails= Get-AzNetworkInterface -ResourceId $nic.Id
$GetNICDetails.EnableAcceleratedNetworking = $true
try
{
Write-Host "Saving NIC..." -ForegroundColor White
Set-AzNetworkInterface -NetworkInterface $GetNICDetails -AsJob | Wait-Job
$sheet.Cells.Item($rowcustname+$i,$colcustname+2)= "Completed"
}
catch
{
Write-Host "------Error Found-------" -ForegroundColor Red
$sheet.Cells.Item($rowcustname+$i,$colcustname+2)= "Error Found"
}
}
}
}
$outputpath="C:\Users\sourabh.majali\Downloads\ExcelSheet_Completed.xlsx"
$workbook.SaveAs($outputpath)
$objExcel.Quit()
#------------------------------------END-------------------------------------------------#
Output
How Script Works?
C:\Users\sourabh.majali\Downloads\ExcelSheet_Completed.xlsx"
Next step would be to check for the errors and resolve the issues accordingly and once this is done, you can check back for the status for all the machine at once if they are reflecting accelerated networking or not using the following script,
$vms= Get-AzVM
foreach($vm in $vms)
{
$nics=$vm.NetworkProfile.NetworkInterfaces
foreach($nic in $nics)
{
Write-Host "--------------------------"
$GetNICDetails= Get-AzNetworkInterface -ResourceId $nic.Id
Write-Host "Checking for ......." $vm.Name
if($GetNICDetails.EnableAcceleratedNetworking -eq "True")
{
Write-Host "Accelerated Networking is enabled.." -ForegroundColor White
}
else
{
Write-Host "Accelerated Networking NOT enabled.." -ForegroundColor Red
}
}
}
Output
Takeaways
In various situations, it becomes necessary to manage and work on multiple machines, sometimes exceeding 100 resources. However, handling these tasks manually can be extremely time-consuming and prone to human error. By automating such processes, significant amounts of time can be saved. Automation also allows for easy tracking of progress and identification of issues, facilitating quick resolution. Additionally, automation enables the creation of comprehensive reports, providing valuable insights into the overall operations.