vite1
Contributor
Contributor

PowerCLI script that lists every IP within vCenter

Jump to solution

I found a script that lists all VM's IPs in vCenter and a command that list vMkernel ports adapter's IPs.

Is there a way that I can put these two together in a script?

## This script lists all VM's IPs

$VMs = get-vmhost | Get-VM
foreach ($VM in $VMs){
    $VMx = Get-View $VM.ID
     $HW = $VMx.guest.net
     foreach ($dev in $HW)
    {
        foreach ($ip in $dev.ipaddress)
        {
            $dev | select @{Name = "Name"; Expression = {$vm.name}},@{Name = "IP"; Expression = {$ip}}, @{Name = "MAC"; Expression = {$dev.macaddress}}
        }
    }
}

And this Command below lists all VMhosts and VMKernel ports IPs.

Get-VMHost | Get-VMHostNetworkAdapter -VMKernel | Select vmhost, name, portgroupname, ip, subnetmask | ft

I would like to have one script or add this command line to the script.  Perhaps some kind of Do next statement??

The goal is to have this script generate one report with all VM IPs and vMKernel Port IPs along with every IP within vCenter that it can query.

Thanks in advance.

1 Solution

Accepted Solutions
LucD
Leadership
Leadership

Sure, it only requires a change in the last line.


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

View solution in original post

0 Kudos
17 Replies
LucD
Leadership
Leadership

Try this, it's a simplified version

$IPaddresses = @()

foreach($vm in Get-VM){
    $vm.Guest.IPAddress | %{
        $IPaddresses += $_
    } }
Get-VMHost | Get-VMHostNetworkAdapter -VMKernel |
%{     $IPaddresses += $_.IP
}
$IPaddresses

It collects all IP addresses in an array.

Note that the use of the Guest property assumes that you have the VMware Tools installed and that all the VMs are powered on.


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

0 Kudos
vite1
Contributor
Contributor

Hi LucD, The script that you listed here only lists IP address, no headers.  I need the headers that it produced before

The script produced this header in an Excel file for the VMs

NameIPMAC

And the command for the Vkernal ports produced this header: (Get-VMHost | Get-VMHostNetworkAdapter -VMKernel | Select vmhost, name, portgroupname, ip, subnetmask | ConvertTo-csv | Set-Content IP_infoTest.csv)

VMHostNamePortGroupNameIPSubnetMask

Both this script and command gave me what I wanted when I generated a report with cmd ConvertTo-csv | Set-Content IP_infoTest.csv.  I like the information it gave me I'm just trying to produce one report with the headers for Hosts, VMs, Kernel ports and whatever IPs I may be missing.  Right now I'm generating two different successful reports with the Script and command that I shared.

Thank you.

0 Kudos
LucD
Leadership
Leadership

My bad, I interpreted that you only wanted the IP addresses.

No problem, the following will give you the Name and the MAC

$IPaddresses = @()

foreach($vm in Get-VM){
    $vm.Guest.Nics | %{
        $row = "" | Select Name, IP, MAC
       
$row.Name = $vm.Name         $row.IP = [String]::Join(',',$_.IPAddress)         $row.MAC = $_.MacAddress         $IPaddresses += $row
    } }
Get-VMHost | Get-VMHostNetworkAdapter -VMKernel | %{     $row = "" | Select Name, IP, MAC
    $row.Name = $_.VMHost.Name     $row.IP = $_.IP     $row.MAC = $_.MAC     $IPaddresses += $row
}
$IPaddresses


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

0 Kudos
vite1
Contributor
Contributor

Hi LucD,

We are getting there, however when I run the script I get this error see below:

I can probably take the time and edit and troubleshoot and get it to work when I have some time.  You though can probably figure it out right away.

Let me know what you think.  Thanks again!!!

    + FullyQualifiedErrorId : PropertyNotFound

Select-Object : A positional parameter cannot be found that accepts argument '$
null'.
At C:\Users\vadmin\Desktop\List_All_IPS.ps1:5 char:27
+         $row = "" | Select <<<<  Name, IP, MAC        $row.Name = $vm.Name
    + CategoryInfo          : InvalidArgument: (:) [Select-Object], ParameterB
   indingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell
   .Commands.SelectObjectCommand

Exception calling "Join" with "2" argument(s): "Value cannot be null.
Parameter name: value"
At C:\Users\vadmin\Desktop\List_All_IPS.ps1:6 char:33
+         $row.IP = [String]::Join <<<< (',',$_.IPAddress)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

Property 'MAC' cannot be found on this object; make sure it exists and is setta
ble.
At C:\Users\vadmin\Desktop\List_All_IPS.ps1:7 char:14
+         $row. <<<< MAC = $_.MacAddress
    + CategoryInfo          : InvalidOperation: (MAC:String) [], RuntimeExcept
   ion
    + FullyQualifiedErrorId : PropertyNotFound

Select-Object : A positional parameter cannot be found that accepts argument '$
null'.
At C:\Users\vadmin\Desktop\List_All_IPS.ps1:5 char:27
+         $row = "" | Select <<<<  Name, IP, MAC        $row.Name = $vm.Name
    + CategoryInfo          : InvalidArgument: (:) [Select-Object], ParameterB
   indingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell
   .Commands.SelectObjectCommand

Exception calling "Join" with "2" argument(s): "Value cannot be null.
Parameter name: value"
At C:\Users\vadmin\Desktop\List_All_IPS.ps1:6 char:33
+         $row.IP = [String]::Join <<<< (',',$_.IPAddress)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

Property 'MAC' cannot be found on this object; make sure it exists and is setta
ble.
At C:\Users\vadmin\Desktop\List_All_IPS.ps1:7 char:14
+         $row. <<<< MAC = $_.MacAddress
    + CategoryInfo          : InvalidOperation: (MAC:String) [], RuntimeExcept
   ion
    + FullyQualifiedErrorId : PropertyNotFound

Select-Object : A positional parameter cannot be found that accepts argument '$
null'.
At C:\Users\vadmin\Desktop\List_All_IPS.ps1:5 char:27
+         $row = "" | Select <<<<  Name, IP, MAC        $row.Name = $vm.Name
    + CategoryInfo          : InvalidArgument: (:) [Select-Object], ParameterB
   indingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell
   .Commands.SelectObjectCommand

Exception calling "Join" with "2" argument(s): "Value cannot be null.
Parameter name: value"
At C:\Users\vadmin\Desktop\List_All_IPS.ps1:6 char:33
+         $row.IP = [String]::Join <<<< (',',$_.IPAddress)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

Property 'MAC' cannot be found on this object; make sure it exists and is setta
ble.
At C:\Users\vadmin\Desktop\List_All_IPS.ps1:7 char:14
+         $row. <<<< MAC = $_.MacAddress
    + CategoryInfo          : InvalidOperation: (MAC:String) [], RuntimeExcept
   ion
    + FullyQualifiedErrorId : PropertyNotFound

Select-Object : A positional parameter cannot be found that accepts argument '$
null'.
At C:\Users\vadmin\Desktop\List_All_IPS.ps1:12 char:23
+     $row = "" | Select <<<<  Name, IP, MAC    $row.Name = $_.VMHost.Name
    + CategoryInfo          : InvalidArgument: (:) [Select-Object], ParameterB
   indingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell
   .Commands.SelectObjectCommand

Property 'IP' cannot be found on this object; make sure it exists and is settab
le.
At C:\Users\vadmin\Desktop\List_All_IPS.ps1:13 char:10
+     $row. <<<< IP = $_.IP
    + CategoryInfo          : InvalidOperation: (IP:String) [], RuntimeExcepti
   on
    + FullyQualifiedErrorId : PropertyNotFound

Property 'MAC' cannot be found on this object; make sure it exists and is setta
ble.
At C:\Users\vadmin\Desktop\List_All_IPS.ps1:14 char:10
+     $row. <<<< MAC = $_.MAC
    + CategoryInfo          : InvalidOperation: (MAC:String) [], RuntimeExcept
   ion
    + FullyQualifiedErrorId : PropertyNotFound

Select-Object : A positional parameter cannot be found that accepts argument '$
null'.
At C:\Users\vadmin\Desktop\List_All_IPS.ps1:12 char:23
+     $row = "" | Select <<<<  Name, IP, MAC    $row.Name = $_.VMHost.Name
    + CategoryInfo          : InvalidArgument: (:) [Select-Object], ParameterB
   indingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell
   .Commands.SelectObjectCommand

Property 'IP' cannot be found on this object; make sure it exists and is settab
le.
At C:\Users\vadmin\Desktop\List_All_IPS.ps1:13 char:10
+     $row. <<<< IP = $_.IP
    + CategoryInfo          : InvalidOperation: (IP:String) [], RuntimeExcepti
   on
    + FullyQualifiedErrorId : PropertyNotFound

Property 'MAC' cannot be found on this object; make sure it exists and is setta
ble.
At C:\Users\vadmin\Desktop\List_All_IPS.ps1:14 char:10
+     $row. <<<< MAC = $_.MAC
    + CategoryInfo          : InvalidOperation: (MAC:String) [], RuntimeExcept
   ion
    + FullyQualifiedErrorId : PropertyNotFound

Select-Object : A positional parameter cannot be found that accepts argument '$
null'.
At C:\Users\vadmin\Desktop\List_All_IPS.ps1:12 char:23
+     $row = "" | Select <<<<  Name, IP, MAC    $row.Name = $_.VMHost.Name
    + CategoryInfo          : InvalidArgument: (:) [Select-Object], ParameterB
   indingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell
   .Commands.SelectObjectCommand

Property 'IP' cannot be found on this object; make sure it exists and is settab
le.
At C:\Users\vadmin\Desktop\List_All_IPS.ps1:13 char:10
+     $row. <<<< IP = $_.IP
    + CategoryInfo          : InvalidOperation: (IP:String) [], RuntimeExcepti
   on
    + FullyQualifiedErrorId : PropertyNotFound

Property 'MAC' cannot be found on this object; make sure it exists and is setta
ble.
At C:\Users\vadmin\Desktop\List_All_IPS.ps1:14 char:10
+     $row. <<<< MAC = $_.MAC
    + CategoryInfo          : InvalidOperation: (MAC:String) [], RuntimeExcept
   ion
    + FullyQualifiedErrorId : PropertyNotFound

Select-Object : A positional parameter cannot be found that accepts argument '$
null'.
At C:\Users\vadmin\Desktop\List_All_IPS.ps1:12 char:23
+     $row = "" | Select <<<<  Name, IP, MAC    $row.Name = $_.VMHost.Name
    + CategoryInfo          : InvalidArgument: (:) [Select-Object], ParameterB
   indingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell
   .Commands.SelectObjectCommand

Property 'IP' cannot be found on this object; make sure it exists and is settab
le.
At C:\Users\vadmin\Desktop\List_All_IPS.ps1:13 char:10
+     $row. <<<< IP = $_.IP
    + CategoryInfo          : InvalidOperation: (IP:String) [], RuntimeExcepti
   on
    + FullyQualifiedErrorId : PropertyNotFound

Property 'MAC' cannot be found on this object; make sure it exists and is setta
ble.
At C:\Users\vadmin\Desktop\List_All_IPS.ps1:14 char:10
+     $row. <<<< MAC = $_.MAC
    + CategoryInfo          : InvalidOperation: (MAC:String) [], RuntimeExcept
   ion
    + FullyQualifiedErrorId : PropertyNotFound

Select-Object : A positional parameter cannot be found that accepts argument '$
null'.
At C:\Users\vadmin\Desktop\List_All_IPS.ps1:12 char:23
+     $row = "" | Select <<<<  Name, IP, MAC    $row.Name = $_.VMHost.Name
    + CategoryInfo          : InvalidArgument: (:) [Select-Object], ParameterB
   indingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell
   .Commands.SelectObjectCommand

Property 'IP' cannot be found on this object; make sure it exists and is settab
le.
At C:\Users\vadmin\Desktop\List_All_IPS.ps1:13 char:10
+     $row. <<<< IP = $_.IP
    + CategoryInfo          : InvalidOperation: (IP:String) [], RuntimeExcepti
   on
    + FullyQualifiedErrorId : PropertyNotFound

Property 'MAC' cannot be found on this object; make sure it exists and is setta
ble.
At C:\Users\vadmin\Desktop\List_All_IPS.ps1:14 char:10
+     $row. <<<< MAC = $_.MAC
    + CategoryInfo          : InvalidOperation: (MAC:String) [], RuntimeExcept
   ion
    + FullyQualifiedErrorId : PropertyNotFound

Select-Object : A positional parameter cannot be found that accepts argument '$
null'.
At C:\Users\vadmin\Desktop\List_All_IPS.ps1:12 char:23
+     $row = "" | Select <<<<  Name, IP, MAC    $row.Name = $_.VMHost.Name
    + CategoryInfo          : InvalidArgument: (:) [Select-Object], ParameterB
   indingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell
   .Commands.SelectObjectCommand

Property 'IP' cannot be found on this object; make sure it exists and is settab
le.
At C:\Users\vadmin\Desktop\List_All_IPS.ps1:13 char:10
+     $row. <<<< IP = $_.IP
    + CategoryInfo          : InvalidOperation: (IP:String) [], RuntimeExcepti
   on
    + FullyQualifiedErrorId : PropertyNotFound

Property 'MAC' cannot be found on this object; make sure it exists and is setta
ble.
At C:\Users\vadmin\Desktop\List_All_IPS.ps1:14 char:10
+     $row. <<<< MAC = $_.MAC
    + CategoryInfo          : InvalidOperation: (MAC:String) [], RuntimeExcept
   ion
    + FullyQualifiedErrorId : PropertyNotFound

Select-Object : A positional parameter cannot be found that accepts argument '$
null'.
At C:\Users\vadmin\Desktop\List_All_IPS.ps1:12 char:23
+     $row = "" | Select <<<<  Name, IP, MAC    $row.Name = $_.VMHost.Name
    + CategoryInfo          : InvalidArgument: (:) [Select-Object], ParameterB
   indingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell
   .Commands.SelectObjectCommand

Property 'IP' cannot be found on this object; make sure it exists and is settab
le.
At C:\Users\vadmin\Desktop\List_All_IPS.ps1:13 char:10
+     $row. <<<< IP = $_.IP
    + CategoryInfo          : InvalidOperation: (IP:String) [], RuntimeExcepti
   on
    + FullyQualifiedErrorId : PropertyNotFound

Property 'MAC' cannot be found on this object; make sure it exists and is setta
ble.
At C:\Users\vadmin\Desktop\List_All_IPS.ps1:14 char:10
+     $row. <<<< MAC = $_.MAC
    + CategoryInfo          : InvalidOperation: (MAC:String) [], RuntimeExcept
   ion
    + FullyQualifiedErrorId : PropertyNotFound

Select-Object : A positional parameter cannot be found that accepts argument '$
null'.
At C:\Users\vadmin\Desktop\List_All_IPS.ps1:12 char:23
+     $row = "" | Select <<<<  Name, IP, MAC    $row.Name = $_.VMHost.Name
    + CategoryInfo          : InvalidArgument: (:) [Select-Object], ParameterB
   indingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell
   .Commands.SelectObjectCommand

Property 'IP' cannot be found on this object; make sure it exists and is settab
le.
At C:\Users\vadmin\Desktop\List_All_IPS.ps1:13 char:10
+     $row. <<<< IP = $_.IP
    + CategoryInfo          : InvalidOperation: (IP:String) [], RuntimeExcepti
   on
    + FullyQualifiedErrorId : PropertyNotFound

Property 'MAC' cannot be found on this object; make sure it exists and is setta
ble.
At C:\Users\vadmin\Desktop\List_All_IPS.ps1:14 char:10
+     $row. <<<< MAC = $_.MAC
    + CategoryInfo          : InvalidOperation: (MAC:String) [], RuntimeExcept
   ion
    + FullyQualifiedErrorId : PropertyNotFound

Select-Object : A positional parameter cannot be found that accepts argument '$
null'.
At C:\Users\vadmin\Desktop\List_All_IPS.ps1:12 char:23
+     $row = "" | Select <<<<  Name, IP, MAC    $row.Name = $_.VMHost.Name
    + CategoryInfo          : InvalidArgument: (:) [Select-Object], ParameterB
   indingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell
   .Commands.SelectObjectCommand

Property 'IP' cannot be found on this object; make sure it exists and is settab
le.
At C:\Users\vadmin\Desktop\List_All_IPS.ps1:13 char:10
+     $row. <<<< IP = $_.IP
    + CategoryInfo          : InvalidOperation: (IP:String) [], RuntimeExcepti
   on
    + FullyQualifiedErrorId : PropertyNotFound

Property 'MAC' cannot be found on this object; make sure it exists and is setta
ble.
At C:\Users\vadmin\Desktop\List_All_IPS.ps1:14 char:10
+     $row. <<<< MAC = $_.MAC
    + CategoryInfo          : InvalidOperation: (MAC:String) [], RuntimeExcept
   ion
    + FullyQualifiedErrorId : PropertyNotFound

0 Kudos
LucD
Leadership
Leadership

It looks as if something went wrong with your copy/paste of the script.

Those should have been 2 lines instead of one.

I attached the script as a file, that should make it easier to copy.


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

0 Kudos
vite1
Contributor
Contributor

LucD:

It worked partially. Where it gave me this:  Much closer! Thanks.

Name                       IP                         MAC
----                       --                         ---
XXXXXXX         123.456.789.1         00:33:33:09:00:01
XXXXXXX                                           00:20:20:39:00:00
XXXXXXX                                           00:10:16:19:00:01

Let me know what you think and I will edit your script on my end.

First it presented this ERROR below before it gave me the output above:

Exception calling "Join" with "2" argument(s): "Value cannot be null.
Parameter name: value"
At C:\Users\vadmin\Desktop\IP-addresses.ps1:7 char:33
+         $row.IP = [String]::Join <<<< (',',$_.IPAddress)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

Exception calling "Join" with "2" argument(s): "Value cannot be null.
Parameter name: value"
At C:\Users\vadmin\Desktop\IP-addresses.ps1:7 char:33
+         $row.IP = [String]::Join <<<< (',',$_.IPAddress)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

Exception calling "Join" with "2" argument(s): "Value cannot be null.
Parameter name: value"
At C:\Users\vadmin\Desktop\IP-addresses.ps1:7 char:33
+         $row.IP = [String]::Join <<<< (',',$_.IPAddress)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

Exception calling "Join" with "2" argument(s): "Value cannot be null.
Parameter name: value"
At C:\Users\vadmin\Desktop\IP-addresses.ps1:7 char:33
+         $row.IP = [String]::Join <<<< (',',$_.IPAddress)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

Exception calling "Join" with "2" argument(s): "Value cannot be null.
Parameter name: value"
At C:\Users\vadmin\Desktop\IP-addresses.ps1:7 char:33
+         $row.IP = [String]::Join <<<< (',',$_.IPAddress)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

Exception calling "Join" with "2" argument(s): "Value cannot be null.
Parameter name: value"
At C:\Users\vadmin\Desktop\IP-addresses.ps1:7 char:33
+         $row.IP = [String]::Join <<<< (',',$_.IPAddress)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

Exception calling "Join" with "2" argument(s): "Value cannot be null.
Parameter name: value"
At C:\Users\vadmin\Desktop\IP-addresses.ps1:7 char:33
+         $row.IP = [String]::Join <<<< (',',$_.IPAddress)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

0 Kudos
LucD
Leadership
Leadership

This is probably caused by what I stated in my first reply, if the VMware Tools are not installed or if the VM has been powered off for a longer period, that IPaddress property will not have any values.

I have adapted the script to deal with the absence of content in the IPaddress property.


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

0 Kudos
vite1
Contributor
Contributor

Good Morning LucD,

Yes, your second one didn't produce the error message; worked great!

Being that I'm just learning PowerCLI and shell (I use to do bash scripting years ago and understand programming to some extent; loops etc.,)  I want to see if I can edit your script to have the output print out this when it hits the hosts and vMkernel.

VMHost          Name            PortGroupName             IP                    SubnetMask
------                    ----            -------------                            --                           ----------
esxi               ... vmk0            Management N...     100.100.1.2            255.255.255.0
esxi                   vmk1            iSCSi                        100.100.1.200       255.255.255.0

Yours produced this:  Sample server and IP names are used below.

Name                                              IP                                                    MAC
----                                                  --                                                         ---
servername                         00.100.200.xx                                 00:50:56:9e:53:f5
servername                         02.100.300.xx                                00:50:56:bd:00:08
Then it presents teh esx hosts:  we used the IP address as a name for the ESX host for now

192.01.xx.xx                         123.456.789.xx                              00.00.11.1a.11.xx

When it hits the hosts I would like it to present the above info mentioned earlier:

    VMHost          Name            PortGroupName             IP                    SubnetMask
------                    ----            -------------                            --                           ----------
esxi               ... vmk0            Management N...     100.100.1.2            255.255.255.0

Again I generated this with a one liner

Get-VMHost | Get-VMHostNetworkAdapter -VMKernel | Select vmhost, name, portgroupname, ip, subnetmask | ConvertTo-csv | Set-Content VMKernelIP_infoTest.csv

Or

Get-VMHost | Get-VMHostNetworkAdapter -VMKernel | Select vmhost, name, portgroupname, ip, subnetmask | ft

Is there a way to make it produce the vm info first with its header:

Name                                              IP                                                    MAC

And then generate another header

VMHost          Name            PortGroupName             IP                    SubnetMask

xxx                   vmk0               abcde                    xxxxxxxxxxxxx       xxxxxxxxxxx

when it produces the VMhost and portgroupss information.

Or is it easier to have the first part of the script run this:

$IPaddresses = @()

foreach($vm in Get-VM){
    $vm.Guest.Nics | %{
        $row = "" | Select Name, IP, MAC
        $row.Name = $vm.Name
        $row.IP = &{if($_.IPAddress){[String]::Join(',',$_.IPAddress)}}
        $row.MAC = $_.MacAddress
        $IPaddresses += $row
    }
}

And now call out to the second module a .ps1 script with

Get-VMHost | Get-VMHostNetworkAdapter -VMKernel | Select vmhost, name, portgroupname, ip, subnetmask | ft

Which will now -append to the above output.

Let me know what you think.

Thanks again for all of your help as I greatly appreciated it!

0 Kudos
LucD
Leadership
Leadership

I'm afraid you can't combine arrays with distinct columns in the same CSV file.

You'll have to use 2 CSV files


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

0 Kudos
vite1
Contributor
Contributor

LucD,

Yes, I see on the array.  THX.

     Is there a way to add the attributes where it prints out on the top header (having one header), the name of the port name "VMK0" portGroupName, and it's IP, subnetMask.  And when it starts querying the info it will just start filling in the info when it gets to the VMkernel part?

If not that is fine.  Like you said I can easily produce two different reports and then just add it to one Excel sheet.

Side note is there a way I can make one script and within it it points to another script (module another .ps1 script) to run next or within it?

Thanks again.

0 Kudos
vite1
Contributor
Contributor

PS.. Hi LucD.  I'm currently training on PowerCLI and I see that you are pulling property names with $_.Ip etc, for filtering with and the where object command as well.   So I'm getting familiar with reading this script.  I'm hooked.

Thanks.

0 Kudos
vite1
Contributor
Contributor

Hi LucD,

A successful attempt:  I was able to get it to print out the property of the Portgroup name by just adding to your script.

Name                              IP                        MAC                                Portgroupname                  

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

TestVM                185.1.2.3               00:11:11:11:00:04                                                

                            

esxi                       192.2.2.2              00:11:11:11:00:04                 Management Network            

esxi                      192.2.4.6               00:00:56:75:00xx                    iSCSi                         

esxi                       192.0.0.x               00:00:55:1x:2b:8                     NFS 

And now when it gets to the host it prints out the vkernel info and IP.  I just have to find the property for the vkernel port name

Name
----
vmk0
??

Great script thank you!  I will award you the correct answer points!!

Thanks again

0 Kudos
vmhyperv
Contributor
Contributor

LucD,

   Can we pull this info in excel CSV format instead of console. ?

Thanks

vmguy

0 Kudos
LucD
Leadership
Leadership

Sure, it only requires a change in the last line.


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

0 Kudos
vmhyperv
Contributor
Contributor

Thanks !!

0 Kudos
vite1
Contributor
Contributor

Good Morning LucD,

I haven’t forgotten about you.  I will close this out with your rewards later on today.  I want to post your script that I edited a little bit to present some different properties and had a question or two.  I will post later on today, so far so great on your script. Thanks again.

0 Kudos
vite1
Contributor
Contributor

Hi Luc D,

Attached is your script edited as I needed the label VMhost name. I know its redundant however now when it starts to parse through the VMhost it will have their names in that specific column.

Thanks again. I credited you points.