Tag Archives: get-macaddress

To find out to which vm a MAC address belongs, you can use a simple one-liner: Get-vm | Select Name, @{N=“Network“;E={$_ | Get-networkAdapter | ? {$_.macaddress -eq“00:50:56:A4:22:F4“}}} |Where {$_.Network-ne “”} (Courtesy of this page: http://www.virtu-al.net/2009/07/07/powercli-more-one-liner-power/ ) Thats really great, and you can easily extend the one-liner to include more data if you like. But for someone who isn’t comfortable with using PowerCLI yet, it can seem a bit terrifying. Therefore I usually create functions for long one-liners like this one. A basic function doing the same thing can look something like this: function Get-MACAddress ($MAC) { Get-vm | Select Name,Folder,PowerState, @{N=”Network”;E={$_ | Get-networkAdapter | ? {$_.macaddress -eq $MAC}}} | Where {$_.Network-ne “”} } That way, it enough to type Get-MACAddress 00:50:56:A1:50:43 Or, you can take the time to create a proper function: function Get-MACAddress { [CmdletBinding()] Param ( [parameter(Mandatory=$True,ValueFromPipeline=$True)][Validatelength(17,17)][string]$MAC, [string]$Location = ‘*’ ) Get-VM -Location $Location | Select Name,Folder,PowerState, @{N=”Network”;E={$_ | Get-networkAdapter…

Read more