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
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
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Good morning,
this script points in the right direction, but I also need the VM-Name in the CSV-File
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
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
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi,
works fine...thx a lot!
Do you know a good Book or something else which discribes PowerCLI for stupid guys like me?
Have a look at my blog article My PS library, in there I mention Hal's book which is the source for PowerCLI!
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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?
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
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi,
that´s nearly a perfect result for me....
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
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
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference