Skip to content

Instantly share code, notes, and snippets.

@vMarkusK
Last active July 13, 2016 13:33
Show Gist options
  • Save vMarkusK/2ef7e37070e054eb2e7e to your computer and use it in GitHub Desktop.
Save vMarkusK/2ef7e37070e054eb2e7e to your computer and use it in GitHub Desktop.
Align Windows Network Name to VM PortGroup Name
if (!(get-pssnapin -name VMware.VimAutomation.Core -erroraction silentlycontinue)) {
add-pssnapin VMware.VimAutomation.Core
}
$i = 1
$GCred = Get-Credential
$VMtoProcess = Get-VM -Name MY-VEEAM-01
Write-Host -foregroundcolor DarkGreen -backgroundcolor white "vSphere Network Config of the VM:"
$VMtoProcess | Get-NetworkAdapter | Select Parent, NetworkName, MacAddress | ft -AutoSize
Write-Host -foregroundcolor DarkGreen -backgroundcolor white "NIC count of the VM:"
$NICcount = ($VMtoProcess | Get-NetworkAdapter).count
$NICcount
while($i -le $NICcount){
$MacAddress = ($VMtoProcess | Get-NetworkAdapter -Name *$i).MacAddress
$NetworkName = ($VMtoProcess | Get-NetworkAdapter -Name *$i).NetworkName
$MacAddressWIN = $MacAddress -replace ":", "-"
$script = 'Get-NetAdapter | Where-Object {$_.MacAddress -eq "' + $MacAddressWIN + '"} | Rename-NetAdapter -NewName ' + $NetworkName + ' -PassThru'
Write-Host -foregroundcolor DarkGreen -backgroundcolor white "InGuest Script to process:"
$script
$VMtoProcess | Invoke-VMScript -ScriptText $Script -GuestCredential $GCred -ScriptType Powershell | Out-Null
$i++
}
$script = 'Get-NetAdapter | Select Name, MacAddress | ft -AutoSize'
Write-Host -foregroundcolor DarkGreen -backgroundcolor white "New InGuest NIC Config:"
$VMtoProcess | Invoke-VMScript -ScriptText $Script -GuestCredential $GCred -ScriptType Powershell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment