Score:0

how export List of all VMs ( VMs network VLANs id ) in Cluster from Vcenter?

in flag

How can I export List of all VMs ( VMs network VLANs id ) in Cluster from Vcenter ? I don't see there any network details option.

Using Vcenter 6.5

enter image description here

I tried this option. I only replaced Get-VirtualPortGroup to Get-VDPortgroup, but not works for me, got some erros

$Portgroups = Get-VDPortgroup |Sort-Object -Unique
$Datastores = Get-Datastore |Sort-Object -Unique
$VMs = get-vm 
[System.Collections.ArrayList]$Output = @()
foreach ($currentVM in $VMs) {
    $VM = New-Object -TypeName PsObject
    $VM | Add-Member -Membertype NoteProperty -Name "Name" -Value $currentVM.Name
    foreach ($Portgroup in $Portgroups) {
        $VM | Add-Member -MemberType NoteProperty -Name $Portgroup.Name -Value (($currentVM|Get-VDPortgroup).name -contains $Portgroup.Name)
    }
    foreach ($Datastore in $Datastores) {
        $VM | Add-Member -MemberType NoteProperty -Name $Datastore.Name -Value (($currentVM|Get-Datastore).name -contains $Datastore.Name)
    }
    $Output += $VM
}
$Output |Export-Csv -Path "vm_export.csv"

error:

Get-VDPortgroup : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.
At line:9 char:93
+ ... rty -Name $Portgroup.Name -Value (($currentVM|Get-VDPortgroup).name - ...
+                                                   ~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (test-vm:PSObject) [Get-VDPortgroup], ParameterBindingException
    + FullyQualifiedErrorId : InputObjectNotBound,VMware.VimAutomation.Vds.Commands.Cmdlets.GetVDPortgroup
Score:1
in flag

You can get every information you need via PowerCLI.

Get-Cluster cluster |
    Get-vm |Get-NetworkAdapter |
    Select Parent,NetworkName,@{name='VlanID';e={(Get-VirtualPortgroup -Name $_.NetworkName |select -First 1).vlanid}} |
    Export-Csv -Path "vm_export.csv"

Getting all portgroups and datastores as separate columns makes it a little more complicated. This works for me:

$Portgroups = Get-VirtualPortGroup |Sort-Object -Unique
$Datastores = Get-Datastore |Sort-Object -Unique
$VMs = get-vm
[System.Collections.ArrayList]$Output = @()
foreach ($currentVM in $VMs) {
    $VM = New-Object -TypeName PsObject
    $VM | Add-Member -Membertype NoteProperty -Name "Name" -Value $currentVM.Name
    foreach ($Portgroup in $Portgroups) {
        $VM | Add-Member -MemberType NoteProperty -Name $Portgroup.Name -Value (($currentVM|Get-VirtualPortGroup).name -contains $Portgroup.Name)
    }
    foreach ($Datastore in $Datastores) {
        $VM | Add-Member -MemberType NoteProperty -Name $Datastore.Name -Value (($currentVM|Get-Datastore).name -contains $Datastore.Name)
    }
    $Output += $VM
}
$Output |Export-Csv -Path "vm_export.csv"
andrew avatar
in flag
Thanks, and what if VM has two NICs, how will be then ? Or how to add also used datastores ?
in flag
In my example you will get a line for every NIC. A VM with three NICs will show up three times. For datastores you can replace Get-NetworkAdapter with Get-Datastore (and use the appropiate properties). To get both in the same line it gets more complicated.
andrew avatar
in flag
Aah, you have right, is showing per line. is possible to show it per column ? NIC1, NIC2 Then how please also add e.g. datastores ? so then I can create my own export. Thanks
in flag
I added an extended example that produces a matrix that has columns for all portgroups and datastores and shows which are connected to wich VM.
andrew avatar
in flag
thanks Gerald, btw do you know why is VM names truncated to 18 characters from basic get-vm command ? how to get full name ? get-vm> This-is-my-test-ma... PoweredOn 2 4.000
in flag
You should ask separate questions for this.
Score:1
tv flag

The easy way is to use rvtool. Just install it on your computer and save an excel report. Then you can filter as you want.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.