Hi! Im trying to find a way of searching for a specific VM by its MAC address... currently i have the following
$global:selection = Read-Host "Please enter MAC address"
Get-Datacenter $global:DCChoice | Get-Cluster $global:CLUChoice | Get-vm | Select Name, @{N=“NIC“;E={$_ | Get-networkAdapter | select Name}}, @{N=“MAC“;E={$_ | Get-networkAdapter | select -ExpandProperty MacAddress}} | Where {$_.MacAddress -eq $global:selection}
everything works up until i pipe through "Where"... any tips?
also, the NIC naming doesnt look right to me? can this be changed to remove the @{Name= }
Name NIC MAC
---- --- ---
VMNAME1 @{Name=Network adapter 1} 00:50:56:B7:C2:5D
Managed to get it working with:
> $global:selection = Read-Host "Please enter MAC address"
> Get-Datacenter $global:DCChoice | Get-Cluster $global:CLUChoice | Get-vm | Get-networkAdapter | Where {$_.MacAddress -like "$global:selection"} | Select Parent, Name, NetworkName, MacAddress
Have a look at Re: Find VMs (and info) from a MAC address txt file
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Managed to get it working with:
> $global:selection = Read-Host "Please enter MAC address"
> Get-Datacenter $global:DCChoice | Get-Cluster $global:CLUChoice | Get-vm | Get-networkAdapter | Where {$_.MacAddress -like "$global:selection"} | Select Parent, Name, NetworkName, MacAddress