如何从 Vcenter 导出集群中所有虚拟机(虚拟机网络 VLAN ID)的列表?我没有看到任何网络详细信息选项。
使用 Vcenter 6.5
我试过这个选项。我只替换Get-VirtualPortGroup
为Get-VDPortgroup
,但对我来说不起作用,出现了一些错误
$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"
错误:
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
答案1
您可以通过 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"
将所有端口组和数据存储作为单独的列会使情况变得稍微复杂一些。这对我来说有效:
$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"
答案2
简单的方法是使用rv工具。只需将其安装在您的计算机上并保存一份 Excel 报告。然后您可以根据需要进行过滤。