I have been using powercli script like below. I am able to fetch VMs informations. But some VMs can have more than one IP such as backup interface , internal interface. I want to display its within VM IP Addresses column. How can I reconstruct my code?
I'm looking to run a PowerCLI script to return a table with the headings as follows:
vCenter | Cluster Name | VMHost | VM | VM IP Addresses | Guest OS | Notes | State | CPU | RAM | Datastores | Disk Space | VMware Tools version
& { foreach ($vCenterServer in $DefaultVIServers)
{
$VMHostTable= @{}
foreach ($VMHostView in (Get-View -Server $vCenterServer -ViewType HostSystem -Property Name))
{
$VMHostTable["$($VMHostView.MoRef.Value)"] = $VMHostView.Name
}
$DatastoreTable = @{}
foreach ($DatastoreView in (Get-View -Server $vCenterServer -ViewType Datastore -Property Name))
{
$DatastoreTable["$($DatastoreView.MoRef.Value)"] = $DatastoreView.Name
}
Get-View -Server $vCenterServer -ViewType VirtualMachine -Filter @{"Config.Template"="False"} -Property Name,
Runtime.Host,
Guest.GuestFullName,
Config.Annotation,
Datastore,
Config.Tools.ToolsVersion |
Select-Object -Property @{N="vCenter";E={$vCenterServer.Name}},
@{N="VMHost";E={$VMHostTable["$($_.Runtime.Host.Value)"]}},
@{N="VM";E={$_.Name}},
@{N="Guest OS";E={$_.Guest.GuestFullName}},
@{N="Notes";E={$_.Config.Annotation}},
@{N="Datastores";E={
$DatastoreNames = foreach ($Datastore in ($_.Datastore))
{$DatastoreTable["$($Datastore.Value)"]}
[string]::Join(',',($DatastoreNames))
}
},
@{N="VMware Tools version";E={$_.Config.Tools.ToolsVersion}}
}
} |
Export-Csv -Path "VMsInfo-$(Get-Date -UFormat '%Y%m%d-%H.%M.%S').csv" -NoTypeInformation -UseCulture -Encoding UTF8
Did you restart the guest OS of the VM after the VMware Tools installation?
Does this return IP address(es) for all VMs?
Get-VM |
Select Name,@{N='IP';E={$_.ExtensionData.Guest.IPAddress -join '|'}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
No luck not returning any value. This is very frustrating. How am i going to troubleshoot this?
Do you see the IP address in the vSphere client or the Web client?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I can see IP address via vsphere client no issue
Are you using IPv6 by any chance?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
We are not using IPv6 address
Then I'm at my wits end I'm afraid
So you see the IP address(es) in the Web Client, but the following doesn't show the IP address(es).
Get-VM |
Select Name,@{N='IP';E={$_.ExtensionData.Guest.IPAddress -join '|'}}
I have no explanation for that behaviour, nor can I recreate that I'm afraid.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc,
I have identified very strange something. I assuming this issue is smells like a BUG regarding VMware vSphere PowerCLI 6.3 Release 1. Because I am running same command on VMware vSphere PowerCLI 5.5 Release 2 Patch 1 And I am able to see IPs for all of those VMs. What do you think about this? Or is there any different syntax for PowerCLI 6.3 ?
Thanks and
Kind Regards,
Well, I ran the same script with PowerCLI 6.3R1 against vSphere 5.5 and 6.0, and in both cases I had the IP addresses in the report.
The syntax should the same, we are accessing a vSphere object, nothing to do with PowerCLI.
Are you using the same PowerShell version in both environments?
What does $psversiontable say?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
PowerCLI 6.3R1 :
PowerCLI C:\> $psversiontable
Name Value
---- -----
PSVersion 5.0.10586.117
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.10586.117
CLRVersion 4.0.30319.34209
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
PowerCLI 5.5 R2 patch 1 on another vCenter Server :
PowerCLI C:\> $psversiontable
Name Value
---- -----
PSVersion 4.0
WSManStackVersion 3.0
SerializationVersion 1.1.0.1
CLRVersion 4.0.30319.34209
BuildVersion 6.3.9600.17400
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion 2.2
A wild guess, can you try the following script in both environments?
Get-VM |
Select Name,
@{N='IP1';E={$_.ExtensionData.Guest.IPAddress -join '|'}},
@{N='IP2';E={$_.ExtensionData.Guest.Net.IpAddress -join '|'}},
@{N='IP3';E={($_.ExtensionData.Guest.Net | %{$_.IPAddress}) -join '|'}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
VMware vSphere PowerCLI 5.5 R2
VMware vSphere PowerCLI 6.3
I just noticed this.
Are these environments pre-5.0?
Can you run this one as well in both environments?
Get-VM |
Select Name,
@{N='IP1';E={$_.ExtensionData.Guest.IPAddress -join '|'}},
@{N='IP2';E={$_.ExtensionData.Guest.Net.IpAddress -join '|'}},
@{N='IP3';E={($_.ExtensionData.Guest.Net | %{$_.IPConfig | %{$_.IPAddress | %{$_.IPAddress}}}) -join '|'}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
No luck I am getting same results. I can continue with VMware PowercLI 5.5 Also I want to add script which reports on any datastores over 90% utilisation I have got script like below. How can I adapted my script ?
foreach ($datastore in (get-datastore | where {$_.name -notlike "*local*" -and [math]::Round(100-($_.freespacegb/$_.capacitygb)*100) -gt 90}))
{
$row = '' | select Name,FreeSpaceGB,CapacityGB,vCenter,PercentUsed
$row.Name = $datastore.name
$row.FreeSpaceGB = $datastore.freespacegb
$row.CapacityGB = $datastore.capacitygb
$row.vCenter = $vcenter.name
$row.PercentUsed = [math]::Round(100-($datastore.freespacegb/$datastore.capacitygb)*100)
$report += $row
I would suggest you create a new thread for that last question.
This thread is already way beyond the thread's title.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD not sure what I'm doing wrong here with this code, each time I run it seems it does the data fetching however when it tries to build the report it starts spitting out errors.
Get-View : Cannot validate argument on parameter 'Id'. The argument is null, empty, or an element of the argument collection contains a null value. Supply a
collection that does not contain any null values and then try the command again.At
C:\Users\Edward\Documents\WindowsPowerShell\Scripts\VM_InventoryLucD2.ps1:41 char:27
+ $t = Get-View $t.Parent -Property Name,Parent -Server $vc
+ ~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-View], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.DotNetInterop.GetVIView
Line 41 of code is: $t = Get-View $t.Parent -Property Name,Parent -Server $vc
Only change I made to the code was the path to the output.
Can you attach the code you are running?
There are a few variations on the script in this thread.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for this awesome script Lucd but how i can see nic connection state for VMs, like is it connected or not ?
Add a line like this
@{N="NIC Connected";E={($vm.config.hardware.device | where {($_.DeviceInfo.Label -like "Network*")}).Connectable.Connected}},
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Lucd, it worked but its not showing if nic status is set to connected at power on, how i can get that ?