PowerCLI

 View Only
  • 1.  Find VMs (and info) from a MAC address txt file

    Posted Jan 25, 2019 02:02 AM

    I'm looking for a way where I can import (get-content) a txt file or a csv that lists mac addresses. The user doesn't know his VM names but does know his mac addresses. I'd like to report back to him the following information in an exported csv file.

    VM Name

    Guest IP address [0]

    VM ID

    Cluster Name

    Mac Address

    vCenter Name

    Sample Data from the txt:

    00:50:56:b8:a4:9a

    00:50:56:92:36:d6

    00:50:56:b8:61:cc

    00:50:56:b8:e6:92

    00:50:56:b8:4f:32

    00:50:56:b8:b5:f0

    00:50:56:b8:f4:cf

    00:50:56:b8:b0:c7



  • 2.  RE: Find VMs (and info) from a MAC address txt file
    Best Answer

    Posted Jan 25, 2019 07:02 AM

    Try something like this

    $macTab = @{}

    Get-VM -PipelineVariable vm | Get-NetworkAdapter |

       ForEach-Object -Process {

       $macTab.Add($_.MacAddress, $vm)

    }


    Get-Content -Path .\mac.txt |

       ForEach-Object -Process {

       $vm = $macTab[$_]

       $_ | Select @{N = 'VM'; E = {$vm.Name}},

       @{N = 'IP'; E = {$vm.Guest.IPAddress[0]}},

       @{N = 'Id'; E = {$vm.Id}},

       @{N = 'Cluster'; E = {(Get-Cluster -VM $vm).Name}},

       @{N = 'Mac'; E = {$_}},

       @{N = 'vCenter'; E = {([uri]$vm.ExtensionData.Client.ServiceUrl).Host}}

    }



  • 3.  RE: Find VMs (and info) from a MAC address txt file

    Posted Jan 25, 2019 02:54 PM

    Hi Luc,

    That worked like a charm. Thank you. Just an FYI I did get the following but still got the information asked for. This worked perfectly for identifying the VMs and which vcenter they are on. I connected to a production and lab vcenters. Thank you once again.

    Exception calling "Add" with "2" argument(s): "Item has already been added. Key in dictionary: '00:50:56:84:5c:db'

    Key being added: '00:50:56:84:5c:db'"

    At line:6 char:4

    +    $macTab.Add($_.MacAddress, $vm)

    +    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

        + FullyQualifiedErrorId : ArgumentException

    Results:

          

    VMIPIdClusterMacvCenter
    app334.so.cg.nms.mlb.inet10.187.215.74VirtualMachine-vm-4976PROD-CG-SO-MLB00:50:56:8B:57:32vc008no
    app093cv.cv.gv.int.net10.187.215.164VirtualMachine-vm-4809PROD-GV-CV-CCA-MLB00:50:56:89:5A:E8vc008no
    mn29.st.vc.nms.mlb.inet10.187.215.40VirtualMachine-vm-9625PROD-VC-ST-MLB00:50:56:B8:3F:01vc008no
    app152ht.ht.ok.int..net10.187.215.196VirtualMachine-vm-4821PROD-OK-HT-CCA-MLB00:50:56:8B:1D:37vc008no
    app094nr.nr.wp.int.net10.187.215.132VirtualMachine-vm-1167PRD-WP-NR-MLB00:50:56:89:1D:35vc008no
    app095nr.nr.wp.int.net10.187.215.134VirtualMachine-vm-9540PRD-WP-NR-MLB00:50:56:B8:03:17vc008no


  • 4.  RE: Find VMs (and info) from a MAC address txt file

    Posted Jan 25, 2019 03:31 PM

    It looks like you might have the same MAC twice in that list.