VMware Cloud Community
TheNakedCloudGu
Contributor
Contributor
Jump to solution

PowerCLi - Syntax to find Host IP Address on VMK0

Hi,

I'm almost sorted on this script I've got to get various details from each hypervisor. However, I'm stuck on the correct syntax to use to get the IP Address;

Get-VMHost |Sort Name |Get-View |

Select Name,

@{N=“Serial number“;E={($_.Hardware.SystemInfo.OtherIdentifyingInfo | where {$_.IdentifierType.Key -eq “ServiceTag”}).IdentifierValue}},

@{N=“Manufacturer“;E={$_.Config.Product.Vendor}},

@{N=“Operating System“;E={$_.Config.Product.Name}},

@{N=“OS Version“;E={$_.Config.Product.Version + “ - Build “ + $_.Config.Product.Build}},

@{N=“Type“;E={$_.Hardware.SystemInfo.Vendor + “ “ + $_.Hardware.SystemInfo.Model}},

@{N=“CPU core count“;E={$_.Hardware.CpuInfo.NumCpuCores}},

@{N=“CPU count“;E={$_.Hardware.CpuInfo.NumCpuPackages}},

@{N=“CPU speed (MHz)“;E={[math]::round($_.Hardware.CpuInfo.Hz / 1000000, 0)}},

@{N=“CPU type“;E={$_.Hardware.CpuPkg[0].Description}},

@{N=“IP Address“;E={$_|Get-VMHostNetworkAdapter.Name.vmk0.IP}},

@{N=“RAM (MB)“;E={“” + (([math]::round($_.Hardware.MemorySize / 1GB, 0))* 1024)}}

Everything else works apart from line 12, which is in bold, to show me the IP Address of vmk0. Been stuck on this for ages and any help would be appreciated as it's just blank...

Many thanks

Graham

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
MKguy
Virtuoso
Virtuoso
Jump to solution

With the Get-View Object you're passing try the following:

@{N=“IP Address“;E={($_.Config.Network.Vnic | ? {$_.Device -eq "vmk0"}).Spec.Ip.IpAddress}},

Get-VMHost myhost22 | Sort Name | Get-View | Select Name,

@{N="IP Address";E={($_.Config.Network.Vnic | ? {$_.Device -eq "vmk0"}).Spec.Ip.IpAddress}}

Name                 IP Address

----                        ----------

myhost22             10.1.1.22

-- http://alpacapowered.wordpress.com

View solution in original post

0 Kudos
8 Replies
LucD
Leadership
Leadership
Jump to solution

Try like this

@{N="IP Address";E={$_|Get-VMHostNetworkAdapter -Name vmk0 | Select -ExpandProperty IP}},


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

TheNakedCloudGu
Contributor
Contributor
Jump to solution

Hi LucD,

Thanks for the speedy response!

I've tried that and I get the following error message;

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 \\vmware-host\Shared Folders\Desktop\PowerShellScripts\CI-ESXi-Data.ps1:line:12 char:48

+ @{N=“IP Address“;E={$_|Get-VMHostNetworkAdapter  <<<< -Name vmk0 | Select -ExpandProperty IP}},

20/05/2014 11:56:35    Get-VMHostNetworkAdapter        VMHostNetworkAdapter with name 'vmk0' was not found using the specified filter(s).   

At \\vmware-host\Shared Folders\Desktop\PowerShellScripts\CI-ESXi-Data.ps1:line:12 char:48

+ @{N=“IP Address“;E={$_|Get-VMHostNetworkAdapter  <<<< -Name vmk0 | Select -ExpandProperty IP}},

Thanks

Graham

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Which PowerCLI build are you using ?

Do a

Get-PowerCLIVersion


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
TheNakedCloudGu
Contributor
Contributor
Jump to solution

Hi LucD,

Here is the output.

PowerCLI Version

----------------

VMware vSphere PowerCLI 5.5 Release 2 build 1671586

---------------

Snapin Versions

---------------

   VMWare AutoDeploy PowerCLI Component 5.5 build 1598391

   VMWare ImageBuilder PowerCLI Component 5.5 build 1598391

   VMware vCloud Director PowerCLI Component 5.5 build 1649227

   VMware License PowerCLI Component 5.5 build 1265954

   VMware VDS PowerCLI Component 5.5 build 1671576

   VMware vSphere PowerCLI Component 5.5 build 1671576

0 Kudos
MKguy
Virtuoso
Virtuoso
Jump to solution

With the Get-View Object you're passing try the following:

@{N=“IP Address“;E={($_.Config.Network.Vnic | ? {$_.Device -eq "vmk0"}).Spec.Ip.IpAddress}},

Get-VMHost myhost22 | Sort Name | Get-View | Select Name,

@{N="IP Address";E={($_.Config.Network.Vnic | ? {$_.Device -eq "vmk0"}).Spec.Ip.IpAddress}}

Name                 IP Address

----                        ----------

myhost22             10.1.1.22

-- http://alpacapowered.wordpress.com
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Ok, I see what happens, you are using the vSphere HostSystem object, not the .Net VMHost object.

Then the solution of will work.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

TheNakedCloudGu
Contributor
Contributor
Jump to solution

Hi MKguy,

That's worked, thanks for your speedy reponse!

I appreciate the help from both you and LucD 🙂

Many thanks!!

Graham

0 Kudos
TheNakedCloudGu
Contributor
Contributor
Jump to solution

Here's the complete and working script!

Get-VMHost |Sort Name |Get-View |

Select Name,

@{N=“Serial number“;E={($_.Hardware.SystemInfo.OtherIdentifyingInfo | where {$_.IdentifierType.Key -eq “ServiceTag”}).IdentifierValue}},

@{N=“Manufacturer“;E={$_.Config.Product.Vendor}},

@{N=“Operating System“;E={$_.Config.Product.Name}},

@{N=“OS Version“;E={$_.Config.Product.Version + “ - Build “ + $_.Config.Product.Build}},

@{N=“Type“;E={$_.Hardware.SystemInfo.Vendor + “ “ + $_.Hardware.SystemInfo.Model}},

@{N=“CPU core count“;E={$_.Hardware.CpuInfo.NumCpuCores}},

@{N=“CPU count“;E={$_.Hardware.CpuInfo.NumCpuPackages}},

@{N=“CPU speed (MHz)“;E={[math]::round($_.Hardware.CpuInfo.Hz / 1000000, 0)}},

@{N=“CPU type“;E={$_.Hardware.CpuPkg[0].Description}},

@{N=“IP Address“;E={($_.Config.Network.Vnic | ? {$_.Device -eq "vmk0"}).Spec.Ip.IpAddress}},

@{N=“RAM (MB)“;E={“” + (([math]::round($_.Hardware.MemorySize / 1GB, 0))* 1024)}} | Export-Csv c:\temp\hostinfo2014-05-20.csv

Thanks

Graham

0 Kudos