none
Need a .csv file including a Machine Pool name, Virtual Machine name, MAC address VLan ID and IPAddress

    Question

  • Using the following script:

    #Add-PSSnapin vmware.vimautomation.core

    Import-Module  vmware.vimautomation.core

    Connect-VIServer XXXXXXXXXX.XXX.xxxxxxnet

    $a = get-vm

     

    $c=@()

    foreach ($aa in $a) {

    $hash=[ordered] @{

        Pool_Name = $aa.Folder.Name

        Machine_Name = $aa.Name

        Vlan = ($aa | Get-NetworkAdapter).NetworkName

        Mac = ($aa | Get-NetworkAdapter).MacAddress

        }

        $c+=New-Object psobject -Property $hash

        }

        $c

    How do I add the row for IP address and how do I edit this script so it wouldn't cut off longer names. Thanks

    Wednesday, June 13, 2018 7:54 AM

All replies

  • Please do not post colored code. Use the code posting tool instead. Thanks.

    This should work ...

    Import-Module  vmware.vimautomation.core
    Connect-VIServer XXXXXXXXXX.XXX.xxxxxxnet
    $a = get-vm
    
    $c = foreach ($aa in $a) {
        $Adapter = $aa | Get-NetworkAdapter
        [PSCustomObject][ordered] @{
            Pool_Name = $aa.Folder.Name
            Machine_Name = $aa.Name
            Vlan = $Adapter.NetworkName
            Mac = $Adapter.MacAddress
            IP = $Adapter.IPAddress
        }
    }
    
    $c
    (untested)


    Best regards,

    (79,108,97,102|%{[char]$_})-join''


    • Edited by BOfH_666 Wednesday, June 13, 2018 8:53 AM
    • Proposed as answer by jrvModerator Wednesday, June 13, 2018 5:29 PM
    Wednesday, June 13, 2018 8:50 AM
  • Hi,

    No, unfortunately it didn't work. Here are the results what I've received:

    Pool_Name          :  2_XXX_Dedidcated

    Machine_Name    :   XXXX-XX0016

    Vlan                    :  XX_XX_XXX_Production_XXX

    Mac                    :   00:50:XX:XX:XX:XX

    IP                       :

    [IP section is blank]

    Friday, June 15, 2018 1:55 AM
  • hmmm ... maybe I should have explained it a little more. The code I posted was just a suggestion. Becaue I don't have a vmware infrastructure I cannot reproduce what you have. You should learn the basics of Powershell. That would make you able to debug or even to extend your scripts. You should pick one vm, use  Get-NetworkAdapter with Get-Member or Select-Object * to figure out the name of the properties. And if one property sounds similar to "IPAddress" you should use this instead of what I showed above in my suggestion.

    Best regards,

    (79,108,97,102|%{[char]$_})-join''

    Friday, June 15, 2018 6:08 AM