Hi folks! I used code found here on another thread and wanted to somewhat alter it to display more information I'm looking for. I'm not familiar with Powershell but plan on learning more. Though I feel the study of powershell is going to take a long time just to figure this simple list of data.
Get-DataCenter testdata | Get-Cluster test |
Get-VM |
ForEach-Object {
$ErrorActionPreference= 'silentlycontinue'
$VM = $_
$VM | Get-VMGuest | Select-Object -ExpandProperty Nics |
&ForEach-Object {
$Nic = $_
foreach ($IP in $Nic.IPAddress)
{
if ($IP.Contains('.'))
{
"" | Select-Object -Property @{Name='VM';Expression={$VM.Name}},
@{Name='IPAddress';Expression={$IP}},
@{Name='NetworkName';Expression={$Nic.NetworkName}},
@{Name='VLANID';Expression={$vlanid.VLanId}}
}
}
}
}
You can see what I have the @{Name VLANID where I'd like to print VLANIDs. I cannot figure out how to not print every VLANID horizontally instead of vertically assigned to each IP address in the list.
Thanks for any assistance!
The VLANid is not available in that object, you will have to fetch the VirtualPortgroup.
Try like this
Get-DataCenter testdata | Get-Cluster test |
Get-VM |
ForEach-Object {
$ErrorActionPreference= 'silentlycontinue'
$VM = $_
$VM | Get-VMGuest | Select-Object -ExpandProperty Nics |
ForEach-Object {
$Nic = $_
$vlan = Get-VirtualPortgroup -Name $nic.NetworkName -VM $VM
foreach ($IP in $Nic.IPAddress)
{
if ($IP.Contains('.'))
{
"" | Select-Object -Property @{Name='VM';Expression={$VM.Name}},
@{Name='IPAddress';Expression={$IP}},
@{Name='NetworkName';Expression={$Nic.NetworkName}},
@{Name='VLANID';Expression={$vlan.VLanId}}
}
}
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The VLANid is not available in that object, you will have to fetch the VirtualPortgroup.
Try like this
Get-DataCenter testdata | Get-Cluster test |
Get-VM |
ForEach-Object {
$ErrorActionPreference= 'silentlycontinue'
$VM = $_
$VM | Get-VMGuest | Select-Object -ExpandProperty Nics |
ForEach-Object {
$Nic = $_
$vlan = Get-VirtualPortgroup -Name $nic.NetworkName -VM $VM
foreach ($IP in $Nic.IPAddress)
{
if ($IP.Contains('.'))
{
"" | Select-Object -Property @{Name='VM';Expression={$VM.Name}},
@{Name='IPAddress';Expression={$IP}},
@{Name='NetworkName';Expression={$Nic.NetworkName}},
@{Name='VLANID';Expression={$vlan.VLanId}}
}
}
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LucD! I had references to the VLADid before posting it, but couldn't figure out what to add after the Get. I have to read up about why "-Name $nic.NetworkName -VM $VM" is significant. Lots to learn. Thanks again!