Automation

 View Only
  • 1.  How to find out MAC / UUID

    Posted Oct 05, 2009 06:31 PM

    Hi,

    i need to export a file which includes the VM-Name, the MAC and the UUID

    I have some command which seem to be interresting, but they´re not doing what I want...

    Get-Network-Adapter VMServerP* shows the following Information of all VM-NetworkAdapters of the VM´s beginning with VMServerP

    example:

    MacAddress : 00:50:56:8c:45:1b

    WakeOnLanEnabled : False

    NetworkName : 192.168.10.0-24

    Type : e1000

    ConnectionState : VMware.VimAutomation.Client20.ConnectInfoImpl

    Id : VirtualMachine-vm-204839/4000

    Name : Network adapter 1

    Get-VM VMServerP* | %{(Get-View $_.Id).config.uuid} simply shows the uuid (without the name of the VM)

    420c6d76-18df-b8dc-b4a8-60d14584aa09

    I would like to get an output as follows (or someting like that, maybe seperated by comma)

    VMServerP1 00:50:56:8c:45:1b 420c6d76-18df-b8dc-b4a8-60d14584aa09

    Can anyone help?

    thx



  • 2.  RE: How to find out MAC / UUID

    Posted Oct 05, 2009 06:44 PM

    You could try something like this

    Get-VM VMServerP* | select @{N="NICname"; E={($_ | Get-NetworkAdapter).Name}},
    				@{N="MAC"; E={($_ | Get-NetworkAdapter).MacAddress}},
    				@{N="UUID"; E={($_ | Get-View).config.uuid}} | Export-Csv "C:\test.csv" -noTypeInformation
    

    The output will be a CSV file.

    If you want the output on the screen remove the Export-Csv cmdlet.



  • 3.  RE: How to find out MAC / UUID

    Posted Oct 06, 2009 08:16 AM

    Good morning,

    this script points in the right direction, but I also need the VM-Name in the CSV-File :smileyhappy:

    This is the actual output:

    NICname,MAC,UUID

    Network

    adapter 1,00:50:56:8c:2b:ef,420c6d76-18df-b8dc-b4a8-60d14584aa09

    Network

    adapter 1,00:50:56:8c:44:05,420c58b2-595d-8ec9-a8d2-e680420d249f

    How do I integrate the VM-Name in the Script?

    Thx



  • 4.  RE: How to find out MAC / UUID
    Best Answer

    Posted Oct 06, 2009 09:33 AM

    No problem

    Get-VM VMServerP* | select @{N="VMname"; E={$_.Name}},
    				@{N="NICname"; E={($_ | Get-NetworkAdapter).Name}},
    				@{N="MAC"; E={($_ | Get-NetworkAdapter).MacAddress}},
    				@{N="UUID"; E={($_ | Get-View).config.uuid}} | Export-Csv "C:\test.csv" -noTypeInformation
    



  • 5.  RE: How to find out MAC / UUID

    Posted Oct 06, 2009 11:14 AM

    Hi,

    works fine...thx a lot!

    Do you know a good Book or something else which discribes PowerCLI for stupid guys like me? :smileyhappy:



  • 6.  RE: How to find out MAC / UUID

    Posted Oct 06, 2009 12:31 PM

    Have a look at my blog article My PS library, in there I mention Hal's book which is the source for PowerCLI!



  • 7.  RE: How to find out MAC / UUID

    Posted Oct 20, 2009 03:53 PM

    Hi,

    the little script works fine.

    Noe I tried to modify it so that it writes the MAC and Guid to the console and then additionally writes the data to the CSV-File. Code at the moment:

    Get-VM Server1 | select @{N="VMname"; E={$_.Name}},

    @{N="MAC"; E={($_ | Get-NetworkAdapter).MacAddress}},

    @{N="UUID"; E={($_ | Get-View).config.uuid}} | Write-Host |Export-Csv "C:\test.csv" -noTypeInformation

    My "Problem" is, that the data is written to the console but it seem´s to me that Write-Host empties the Pipeline, right? So Export-CSV gets no data

    and creates an empty file,right?



  • 8.  RE: How to find out MAC / UUID

    Posted Oct 20, 2009 05:31 PM

    That is sort of correct. The Write-Host cmdlet doesn't put any thing on the pipeline, hence the following Export-Csv has no incoming data in the pipeline.

    There are several solutions for this. Just 2 of them.

    1) You can use a the Foreach-Object cmdlet and the semi-colon

    Get-VM Server1 | select @{N="VMname"; E={$_.Name}},
    @{N="MAC"; E={($_ | Get-NetworkAdapter).MacAddress}},
    @{N="UUID"; E={($_ | Get-View).config.uuid}} | %{$_ | Write-Host; $_|Export-Csv "C:\test.csv" -noTypeInformation}
    

    2) You can abandon the one-liner and store the result in a variable.

    Something like this

    $var = Get-VM Server1 | select @{N="VMname"; E={$_.Name}},
    @{N="MAC"; E={($_ | Get-NetworkAdapter).MacAddress}},
    @{N="UUID"; E={($_ | Get-View).config.uuid}}
    $var | Write-Host
    $var | Export-Csv "C:\test.csv" -noTypeInformation
    



  • 9.  RE: How to find out MAC / UUID

    Posted Oct 21, 2009 09:08 AM

    Hi,

    that´s nearly a perfect result for me.... :smileyhappy:

    But is there a parameter für Export-CSV which tells it to add a new line to the file if it already exists?

    At the moment the file will be overwritten.

    Thx

    Chakoe



  • 10.  RE: How to find out MAC / UUID

    Posted Oct 21, 2009 10:00 AM

    The Export-Csv cmdlet doesn't have an "append" option but you can first read in the file and then add the new data.

    Something like this

    $report = @(Import-Csv "C:\Test.csv")
    
    $var = Get-VM <your-VM> | select @{N="VMname"; E={$_.Name}},
    @{N="MAC"; E={($_ | Get-NetworkAdapter).MacAddress}},
    @{N="UUID"; E={($_ | Get-View).config.uuid}}
    $var | Write-Host
    $report += $var
    $report | Export-Csv "C:\test.csv" -noTypeInformation