PowerCLI

 View Only
Expand all | Collapse all

Need a powershell script for collecting ESX host information

RvdNieuwendijk

RvdNieuwendijkMar 31, 2010 06:17 AM

Sureshadmin

SureshadminJun 05, 2010 05:37 AM

Sureshadmin

SureshadminJun 14, 2010 12:11 AM

  • 1.  Need a powershell script for collecting ESX host information

    Posted Mar 29, 2010 05:44 AM

    Hi,

    I need a powershell script to collect the below given ESX host information from the Virtual Center. My environment VC:2.5, ESX hosts: 2.5, 3, 3.5

    At present i have individual powershell one liner scripts for getting these details. Would be more useful to have a single script. Tried VESI, but not getting the report in the below given format.

    ESX host name | Version | Build Number | Manufacturer | Model | Processor Type | Physical CPU count | Cores Count | Service Console IP | vMotion IP | HBA count | Physical NICS count

    Thanks in advance!



  • 2.  RE: Need a powershell script for collecting ESX host information

    Posted Mar 29, 2010 06:41 AM

    Try this

    Get-VMHost  | Select Name, Version,
    	Build, Manufacturer, Model, ProcessorType,
    	NumCPU, @{N="Cores";E={($_| Get-View).Hardware.CpuInfo.NumCpuCores}},
    	@{N="Service Console IP";E={(($_|Get-VMHostNetwork).ConsoleNic | Select IP).IP}},
    	@{N="vMotion IP";E={(($_|Get-VMHostNetwork).VirtualNic | Select IP).IP}},
    	@{N="HBA count";E={($_| Get-VMHostHba | where {$_.Type -eq "FibreChannel"}).Count}},
    	@{N="Physical NICS count";E={($_ | Get-View).Config.Network.Pnic.Count}}
    

    For the Cores field I wasn't sure if you want the number of cores per processor block or the total number of cores on the server.

    It now shows the cores per processor block.

    ____________

    Blog: LucD notes

    Twitter: lucd22



  • 3.  RE: Need a powershell script for collecting ESX host information

    Posted Mar 31, 2010 01:51 AM

    hi Lucd,

    This script works perfectly on ESX 3.5.

    But in ESX 2.5, 3 and 4 it doesn't give values for Service console IP, vMotion IP and HBA count.

    Any ideas?



  • 4.  RE: Need a powershell script for collecting ESX host information

    Posted Mar 31, 2010 05:15 AM

    Works ok on ESX 4 for me.

    For the HBA count I only select the FC HBAs, if you want to see other HBAs you can leave out the Where cmdlet on that line.

    For the console and vkernel IP address there was a typo.

    This should work for ESX 4

    Get-VMHost <esx-name> | Select Name, Version,
    	Build, Manufacturer, Model, ProcessorType,
    	NumCPU, @{N="Cores";E={($_| Get-View).Hardware.CpuInfo.NumCpuCores}},
    	@{N="Service Console IP";E={($_|Get-VMHostNetwork).ConsoleNic[0].IP}},
    	@{N="vMotion IP";E={($_|Get-VMHostNetwork).VirtualNic[0].IP}},
    	@{N="HBA count";E={($_| Get-VMHostHba | where {$_.Type -eq "FibreChannel"}).Count}},
    	@{N="Physical NICS count";E={($_ | Get-View).Config.Network.Pnic.Count}}
    

    Since there are square brackets involved and since the forum SW has problems with these, I attached the script.

    Unfortunately I don't have an ESX 2.5 or 3 to test.

    ____________

    Blog: LucD notes

    Twitter: lucd22



  • 5.  RE: Need a powershell script for collecting ESX host information

    Posted Mar 31, 2010 06:17 AM

    I tested Luc's script on ESX 3.5 and it works ok.



  • 6.  RE: Need a powershell script for collecting ESX host information

    Posted Apr 01, 2010 05:15 AM

    hi Lucd,

    Can you please clarify how numCpu and cores count are calculated. I assume numCpu is physical processor count and cores count is cores per physical processor.

    But in the report i see for many esx host the values for numCpu and Cores count are 8 and 8. Just confused, how is it calculated?

    Also i have sent you a Private Message. Please check it.



  • 7.  RE: Need a powershell script for collecting ESX host information

    Posted Apr 01, 2010 05:37 AM

    The script gets the NumCPU value from the HostSystemImpl object that is returned by Get-VMHost.

    This seems indeed to return the number of cores and not the number of physical processors.

    Try this

    Get-VMHost <esx-name> | Select Name, Version,
    	Build, Manufacturer, Model, ProcessorType,
    	@{N="NumCPU";E={($_| Get-View).Hardware.CpuInfo.NumCpuPackages}},
    	@{N="Cores";E={($_| Get-View).Hardware.CpuInfo.NumCpuCores}},
    	@{N="Service Console IP";E={($_|Get-VMHostNetwork).ConsoleNic[0].IP}},
    	@{N="vMotion IP";E={($_|Get-VMHostNetwork).VirtualNic[0].IP}},
    	@{N="HBA count";E={($_| Get-VMHostHba | where {$_.Type -eq "FibreChannel"}).Count}},
    	@{N="Physical NICS count";E={($_ | Get-View).Config.Network.Pnic.Count}}
    

    Now the NumCPU value is retrieved from the HostCpuInfo object.

    ____________

    Blog: LucD notes

    Twitter: lucd22



  • 8.  RE: Need a powershell script for collecting ESX host information

    Posted Apr 02, 2010 01:57 AM

    Luc,

    Now the script gives correct CPU and core values. So ESX 3.5 reporting is perfect now.

    In ESX 4, now it displays values for vMotion IP and HBA count, but Service Console IP value is blank.

    I have posted one more script requirement in http://communities.vmware.com/thread/262425 Please check whether do u have this script.



  • 9.  RE: Need a powershell script for collecting ESX host information

    Posted Apr 02, 2010 07:03 AM

    Strange, it gives correct results in my environment.

    Are you sure the square brackets are included?

    Try the attached file.

    ____________

    Blog: LucD notes

    Twitter: lucd22



  • 10.  RE: Need a powershell script for collecting ESX host information

    Posted Apr 03, 2010 02:16 AM

    I checked whether square brackets are present. It's there.

    I use VESI and also tried to execute from powercli console, but in both cases service console IP field is blank in ESX4.

    I tried to attach the screenshots of the script and output, First time i got error "You are unauthorized to perform this operation, contact moderator" and message alone got posted without attachements. Tried second time but got a error "File is too large" for just 14Kb and 4kb gif files. i think forum software has a bug :smileysad:



  • 11.  RE: Need a powershell script for collecting ESX host information

    Posted Apr 03, 2010 08:53 AM

    Could you perhaps show the output of the following line ?

    Get-VMHost <esx-hostname> | Get-VMHostNetwork | Select -ExpandProperty ConsoleNic
    

    Run it from the PowerCLI prompt and paste in the result.

    ____________

    Blog: LucD notes

    Twitter: lucd22



  • 12.  RE: Need a powershell script for collecting ESX host information

    Posted Apr 06, 2010 02:03 PM

    Luc,

    I used connect-viserver and connected to my ESX4 box. Then i ran the command given by you. But it gave no output. Just pasted it below.

    C:\Program Files\VMware\Infrastructure\vSphere PowerCLI> Get-

    VMHost | Get-VMHostNetwork | Select -ExpandProperty ConsoleNic

    C:\Program Files\VMware\Infrastructure\vSphere PowerCLI>



  • 13.  RE: Need a powershell script for collecting ESX host information

    Posted Apr 06, 2010 02:51 PM

    Are you running the latest PowerCLI build ?

    Does

    Get-PowerCLIVersion
    

    return

    PowerCLI Version
    ----------------
    VMware vSphere PowerCLI 4.0 U1 build 208462
    

    ____________

    Blog: LucD notes

    Twitter: lucd22



  • 14.  RE: Need a powershell script for collecting ESX host information

    Posted Apr 06, 2010 03:25 PM

    yes Luc,

    I upgraded recently when i installed VESI and windows powershell version is 1

    C:\> Get-PowerCLIVersion

    PowerCLI Version

    -


    VMware vSphere PowerCLI 4.0 U1 build 208462



  • 15.  RE: Need a powershell script for collecting ESX host information
    Best Answer

    Posted Apr 06, 2010 04:05 PM

    Then I'm at my wits end here.

    It works for me and Robert also confirmed it worked for him.

    Although I can't see why this would solve the problem, you could ultimately try an upgrade to PowerShell v2 RTM.

    ____________

    Blog: LucD notes

    Twitter: lucd22



  • 16.  RE: Need a powershell script for collecting ESX host information

    Posted Apr 07, 2010 12:37 PM

    Luc,

    I can live with this script for now because my major requirement ESX3.5. I will upgrade powershell and give out a try once on ESX4. Thanks for this script, it has helped me a lot. Still i have 2 more script requirement will post it soon.

    Given correct answer 10 points and helpful answers



  • 17.  RE: Need a powershell script for collecting ESX host information

    Posted Aug 20, 2012 06:30 PM

    Below script is all Good and I love it. But it is missing the Total memory configured on the ESX host. how can I get this using the same script.

    ANy help in this regard will be appreciated.

    Connect-VIServer <server> -User <user> -Password <password>
    $HostReport = @()
    Get-VMHost |Get-View |%{    
         $Report = "" | select Hostname, version, Build, manufacture, Model,cpu_model, core_num, ip_address,vmotion_ip, HBA_num, P_nic
         $Report.Hostname = $_.Name
         $Report.version =$_.Config.Product.Version
         $Report.Build =$_.Config.Product.Build
         $Report.manufacture =$_.Hardware.SystemInfo.Vendor
         $Report.Model =$_.Hardware.SystemInfo.Model
         $Report.cpu_model =$_.Summary.Hardware.CpuModel
         $Report.core_num =$_.Hardware.CpuInfo.NumCpuCores
         if($Report.version -like "3.5.*"){
              $Report.ip_address =$_.Config.Network.ConsoleVnic.Spec.ip.ipaddress
         }
         else {$Report.ip_address =$_.Config.Network.ConsoleVnic[0].Spec.ip.ipaddress}
         $Report.vmotion_ip =$_.Config.Vmotion.IpConfig.IpAddress
         $Report.HBA_num =$_.Summary.Hardware.NumHBAs
         $Report.P_nic =$_.Config.Network.Pnic.count
         $HostReport += $Report
    }
    $HostReport | Export-Csv "C:\HostReport.csv" –NoTypeInformation



  • 18.  RE: Need a powershell script for collecting ESX host information

    Posted Aug 20, 2012 06:44 PM

    Try this

    Connect-VIServer <server> -User <user> -Password <password> 
    $HostReport
    = @() Get-VMHost |%{          $Report = "" | select Hostname, version, Build, manufacture, Model,cpu_model, core_num, totalmemoryMB, ip_address,vmotion_ip, HBA_num, P_nic
        
    $Report.Hostname = $_.Name      $Report.version =$_.Version      $Report.Build =$_.Build      $Report.manufacture =$_.ExtensionData.Hardware.SystemInfo.Vendor      $Report.Model =$_.Model      $Report.cpu_model =$_.ExtensionData.Summary.Hardware.CpuModel      $Report.core_num =$_.ExtensionData.Hardware.CpuInfo.NumCpuCores      $Report.totalmemoryMB =$_.MemoryTotalMB      if($Report.version -like "3.5.*"){           $Report.ip_address =$_.ExtensionData.Config.Network.ConsoleVnic.Spec.ip.ipaddress      }      else {$Report.ip_address =$_.ExtensionData.Config.Network.ConsoleVnic[0].Spec.ip.ipaddress}      $Report.vmotion_ip =$_.ExtensionData.Config.Vmotion.IpConfig.IpAddress
         $Report.HBA_num =$_.ExtensionData.Summary.Hardware.NumHBAs
        
    $Report.P_nic =$_.ExtensionData.Config.Network.Pnic.count      $HostReport += $Report
    } $HostReport | Export-Csv "C:\HostReport.csv" NoTypeInformation


  • 19.  RE: Need a powershell script for collecting ESX host information

    Posted Aug 20, 2012 07:23 PM

    Thanks a lot and I really appreciate this. Hats Off to you for supporting people like us, even after many years with similar questions.

    Is it possible to List the cluster name to the output file where each ESX host resides?

    Since Get-Cluster and Get-vmhost are different, how do we do this?

    Also, one last question,

    How do you get ( learn or understand) the property value for each object? For example, $_.ExtensionData.Config.Network.Pnic.count



  • 20.  RE: Need a powershell script for collecting ESX host information

    Posted Apr 16, 2010 04:16 PM

    Luc,

    Need your help here. Can you please include the cluster name in the script. So the expected output looks like this.

    ESX host name | Version | Build Number | Cluster Name | Manufacturer | Model | Processor Type | Physical CPU count | Cores Count | Service Console IP | vMotion IP | HBA count | Physical NICS count

    If the ESX box does not belong to cluster this field can be blank.

    Or, if you have a script to give out cluster wise esx host details, it is also ok for me.



  • 21.  RE: Need a powershell script for collecting ESX host information

    Posted Apr 16, 2010 05:14 PM

    Sure, try this

    Get-VMHost | Select Name, Version,
    	Build, 
    	@{N="Cluster Name";E={($_ | Get-Cluster).Name}},
    	Manufacturer, Model, ProcessorType,
    	@{N="NumCPU";E={($_| Get-View).Hardware.CpuInfo.NumCpuPackages}},
    	@{N="Cores";E={($_| Get-View).Hardware.CpuInfo.NumCpuCores}},
    	@{N="Service Console IP";E={($_|Get-VMHostNetwork).ConsoleNic[0].IP}},
    	@{N="vMotion IP";E={($_|Get-VMHostNetwork).VirtualNic[0].IP}},
    	@{N="HBA count";E={($_| Get-VMHostHba | where {$_.Type -eq "FibreChannel"}).Count}},
    	@{N="Physical NICS count";E={($_ | Get-View).Config.Network.Pnic.Count}}
    

    ____________

    Blog: LucD notes

    Twitter: lucd22



  • 22.  RE: Need a powershell script for collecting ESX host information

    Posted Apr 16, 2010 08:23 PM

    Thank you so much :smileyhappy: . If possible, whenever you have time please have a look at my storage script requirement.



  • 23.  RE: Need a powershell script for collecting ESX host information

    Posted Apr 17, 2010 05:14 AM

    Luc,

    Posted a requirement for script to collect VM information. Please have a look http://communities.vmware.com/thread/264441



  • 24.  RE: Need a powershell script for collecting ESX host information

    Posted May 27, 2010 02:36 PM

    Luc,

    Can you please give a script to list the below info from Virtual center,

    VM name | ESX Name | Cluster name

    If the vm is not part of the cluster please leave the value as blank.



  • 25.  RE: Need a powershell script for collecting ESX host information

    Posted May 27, 2010 04:04 PM

    Sure, try this

    Get-VM | Select @{N="VM name";E={$_.Name}},
    	@{N="ESX name";E={($_ | Get-VMHost).Name}},
    	@{N="Cluster name";E={($_ | Get-Cluster).Name}}
    

    ____________

    Blog: LucD notes

    Twitter: lucd22



  • 26.  RE: Need a powershell script for collecting ESX host information

    Posted May 28, 2010 03:46 AM

    Thank you so much.



  • 27.  RE: Need a powershell script for collecting ESX host information

    Posted Jun 04, 2010 03:06 PM

    Luc,

    Need a help. Can you please add 2 more fields in this script

    vSwitches ---> print names of all vswitch in the esx box seperated by commas.

    Portgroups -


    > print names of all portgroups in all switches seperated by commas.



  • 28.  RE: Need a powershell script for collecting ESX host information

    Posted Jun 04, 2010 03:55 PM

    Here you go.

    ____________

    Blog: LucD notes

    Twitter: lucd22



  • 29.  RE: Need a powershell script for collecting ESX host information

    Posted Jun 05, 2010 05:37 AM

    Works perfect. Thanks a lot.



  • 30.  RE: Need a powershell script for collecting ESX host information

    Posted Jun 09, 2010 03:30 PM

    Nice script, whould it be possible to add basic Iscsi information like ip address for each HBA adaptor ? It would also be nice to send the result to a csv. or word document.



  • 31.  RE: Need a powershell script for collecting ESX host information

    Posted Jun 09, 2010 09:15 PM

    Do you mean the IP address of the IScsi targets ?

    Like this ?

    Get-VMHost | Get-View | %{
    	$esx = $_
    	$esx.Config.StorageDevice.HostBusAdapter | where {$_.GetType().Name -eq "HostInternetScsiHba"} | %{
    		$hba = $_
    		$_.ConfiguredSendTarget | `
    			Select @{N="ESX Name";E={$esx.Name}},
    			@{N="HBA Device";E={$hba.Device}},
    			@{N="IScsi Name";E={$hba.IScsiName}},
    			@{N="IScsi Target";E={$_.Address}}
    	}
    } | Export-Csv "C:\IScsi.csv" -NoTypeInformation -UseCulture
    

    To store this result on a worksheet in a XLS file have a look at my Beyond Export-Csv: Export-Xls post.

    ____________

    Blog: LucD notes

    Twitter: lucd22



  • 32.  RE: Need a powershell script for collecting ESX host information

    Posted Jun 10, 2010 12:13 PM

    no, I mean the ip address of the Iscsi Adaptor in the ESX server.



  • 33.  RE: Need a powershell script for collecting ESX host information

    Posted Jun 12, 2010 12:31 AM

    Luc,

    Can you please add 2 more fields to this script,

    Datastores ---> The name of all datastores that ESX can see separated by commas.

    WWN ---> The WWN of all HBA cards seperated by commas.



  • 34.  RE: Need a powershell script for collecting ESX host information

    Posted Jun 12, 2010 08:13 AM

    Here you go.

    Note that I added a 3th field, called "FC Devices", that will allow you see which "FC WWN" belongs to which HBA.

    ____________

    Blog: LucD notes

    Twitter: lucd22



  • 35.  RE: Need a powershell script for collecting ESX host information

    Posted Jun 12, 2010 06:16 PM

    Luc,

    Thank you so much.

    Can you please change the output of the datastore field to show capacity as well like given below.

    DatastoreName(CapacityInGB)

    Example: vmfs12(200), vmfs13(250)



  • 36.  RE: Need a powershell script for collecting ESX host information

    Posted Jun 13, 2010 10:37 AM

    Try this.

    ____________

    Blog: LucD notes

    Twitter: lucd22



  • 37.  RE: Need a powershell script for collecting ESX host information

    Posted Jun 14, 2010 12:11 AM

    Yes, working fine. Thank you so much, Luc.



  • 38.  RE: Need a powershell script for collecting ESX host information

    Posted Jun 14, 2010 02:26 PM

    Luc, this is what I was looking for but since I don't know how to program I don't know how to add the ip target to the result.

    VMHost | Get-View | %{

    $esx = $_

    $esx.Config.StorageDevice.HostBusAdapter | where {$_.GetType().Name -eq "HostInternetScsiHba"} | %{

    $hba = $_

    $_.ipProperties |`

    Select @{N="ESX Name";E={$esx.Name}},

    @{N="HBA Device";E={$hba.Device}},

    @{N="IScsi IP";E={$_.Address}}

    }

    $_.ConfiguredSendTarget |`

    Select @{N="IScsi IP";E={$_.Address}}

    } | Out-GridView

    when it comes to programming, the best I can do is change lines or adding stuff coming from others script, but I don't really know what I do.



  • 39.  RE: Need a powershell script for collecting ESX host information

    Posted Jun 14, 2010 04:29 PM

    You can get those line in the script like this

    Get-VMHost | Select Name, Version,
    	Build, 
    	@{N="Cluster Name";E={($_ | Get-Cluster).Name}},
    	Manufacturer, Model, ProcessorType,
    	@{N="NumCPU";E={($_| Get-View).Hardware.CpuInfo.NumCpuPackages}},
    	@{N="Cores";E={($_| Get-View).Hardware.CpuInfo.NumCpuCores}},
    	@{N="Service Console IP";E={($_|Get-VMHostNetwork).ConsoleNic[0].IP}},
    	@{N="vMotion IP";E={($_|Get-VMHostNetwork).VirtualNic[0].IP}},
    	@{N="HBA count";E={($_| Get-VMHostHba | where {$_.Type -eq "FibreChannel"}).Count}},
    	@{N="DatastoreName(Capacity in GB)";E={[string]::Join(",",( $_ | Get-Datastore | %{$_.Name + "(" + ("{0:f1}" -f ($_.CapacityMB/1KB)) + ")"}))}},
    	@{N="FC Device";E={[string]::Join(",",(($_ | Get-View).Config.StorageDevice.HostBusAdapter | where{$_.GetType().Name -eq "HostFibreChannelHba"} | %{$_.Device}))}},
    	@{N="FC WWN";E={[string]::Join(",",(($_ | Get-View).Config.StorageDevice.HostBusAdapter | where{$_.GetType().Name -eq "HostFibreChannelHba"} | %{"{0:x}" -f $_.NodeWorldWideName}))}},
    	@{N="Physical NICS count";E={($_ | Get-View).Config.Network.Pnic.Count}},
    	@{N="vSwitches";E={[string]::Join(",",( $_ | Get-VirtualSwitch | %{$_.Name}))}},
    	@{N="Portgroups";E={[string]::Join(",",( $_ | Get-VirtualPortGroup | %{$_.Name}))}},
    	@{N="IScsi HBA Name";E={[string]::Join(",",(($_| Get-View).Config.StorageDevice.HostBusAdapter | where {$_.GetType().Name -eq "HostInternetScsiHba"} | %{$_.Device}))}},
    	@{N="IScsi IP addr";E={[string]::Join(",",(($_| Get-View).Config.StorageDevice.HostBusAdapter | where {$_.GetType().Name -eq "HostInternetScsiHba"} | %{$_.ipProperties.address}))}}
    

    But I think the IP address won't be in the property when it concerns a "soft" IScsi setup.

    ____________

    Blog: LucD notes

    Twitter: lucd22



  • 40.  RE: Need a powershell script for collecting ESX host information

    Posted Jun 14, 2010 04:46 PM

    Great it's working. I don't really care about soft iniator since we are not using it. I have been trying to make this work by myself for the past 4 hours. I was not so far from what you post. Thank you very much this will be very helpfull.

    Question: adding Out-GridView or Export-Csv and the end of the script would probably not work ?



  • 41.  RE: Need a powershell script for collecting ESX host information

    Posted Jun 14, 2010 05:01 PM

    You can add Export-Csv or Out-GridView without a problem.

    Like this

    Get-VMHost | Select Name, Version,
    	Build, 
    	@{N="Cluster Name";E={($_ | Get-Cluster).Name}},
    	Manufacturer, Model, ProcessorType,
    	@{N="NumCPU";E={($_| Get-View).Hardware.CpuInfo.NumCpuPackages}},
    	@{N="Cores";E={($_| Get-View).Hardware.CpuInfo.NumCpuCores}},
    	@{N="Service Console IP";E={($_|Get-VMHostNetwork).ConsoleNic[0].IP}},
    	@{N="vMotion IP";E={($_|Get-VMHostNetwork).VirtualNic[0].IP}},
    	@{N="HBA count";E={($_| Get-VMHostHba | where {$_.Type -eq "FibreChannel"}).Count}},
    	@{N="DatastoreName(Capacity in GB)";E={[string]::Join(",",( $_ | Get-Datastore | %{$_.Name + "(" + ("{0:f1}" -f ($_.CapacityMB/1KB)) + ")"}))}},
    	@{N="FC Device";E={[string]::Join(",",(($_ | Get-View).Config.StorageDevice.HostBusAdapter | where{$_.GetType().Name -eq "HostFibreChannelHba"} | %{$_.Device}))}},
    	@{N="FC WWN";E={[string]::Join(",",(($_ | Get-View).Config.StorageDevice.HostBusAdapter | where{$_.GetType().Name -eq "HostFibreChannelHba"} | %{"{0:x}" -f $_.NodeWorldWideName}))}},
    	@{N="Physical NICS count";E={($_ | Get-View).Config.Network.Pnic.Count}},
    	@{N="vSwitches";E={[string]::Join(",",( $_ | Get-VirtualSwitch | %{$_.Name}))}},
    	@{N="Portgroups";E={[string]::Join(",",( $_ | Get-VirtualPortGroup | %{$_.Name}))}},
    	@{N="IScsi HBA Name";E={[string]::Join(",",(($_| Get-View).Config.StorageDevice.HostBusAdapter | where {$_.GetType().Name -eq "HostInternetScsiHba"} | %{$_.Device}))}},
    	@{N="IScsi IP addr";E={[string]::Join(",",(($_| Get-View).Config.StorageDevice.HostBusAdapter | where {$_.GetType().Name -eq "HostInternetScsiHba"} | %{$_.ipProperties.address}))}} | `
    Out-GridView
    

    You pipe the output of the Select-Object cmdlet to the Out-GridView or Export-Csv cmdlet.

    ____________

    Blog: LucD notes

    Twitter: lucd22



  • 42.  RE: Need a powershell script for collecting ESX host information

    Posted Jun 14, 2010 05:05 PM

    Great it's working, I tried it before but it didn't worked. I must have made a mistake somewhere.

    Thanks again.



  • 43.  RE: Need a powershell script for collecting ESX host information

    Posted Jun 15, 2010 02:59 AM

    hi Luc,

    Can you please alter the output of vSwitch field like vSwitchName(no. of ports)

    Eg. vSwitch1(56)



  • 44.  RE: Need a powershell script for collecting ESX host information

    Posted Jun 15, 2010 04:54 AM

    There you go.

    Get-VMHost | Select Name, Version,
    	Build, 
    	@{N="Cluster Name";E={($_ | Get-Cluster).Name}},
    	Manufacturer, Model, ProcessorType,
    	@{N="NumCPU";E={($_| Get-View).Hardware.CpuInfo.NumCpuPackages}},
    	@{N="Cores";E={($_| Get-View).Hardware.CpuInfo.NumCpuCores}},
    	@{N="Service Console IP";E={($_|Get-VMHostNetwork).ConsoleNic[0].IP}},
    	@{N="vMotion IP";E={($_|Get-VMHostNetwork).VirtualNic[0].IP}},
    	@{N="HBA count";E={($_| Get-VMHostHba | where {$_.Type -eq "FibreChannel"}).Count}},
    	@{N="DatastoreName(Capacity in GB)";E={[string]::Join(",",( $_ | Get-Datastore | %{$_.Name + "(" + ("{0:f1}" -f ($_.CapacityMB/1KB)) + ")"}))}},
    	@{N="FC Device";E={[string]::Join(",",(($_ | Get-View).Config.StorageDevice.HostBusAdapter | where{$_.GetType().Name -eq "HostFibreChannelHba"} | %{$_.Device}))}},
    	@{N="FC WWN";E={[string]::Join(",",(($_ | Get-View).Config.StorageDevice.HostBusAdapter | where{$_.GetType().Name -eq "HostFibreChannelHba"} | %{"{0:x}" -f $_.NodeWorldWideName}))}},
    	@{N="Physical NICS count";E={($_ | Get-View).Config.Network.Pnic.Count}},
    	@{N="vSwitches(Number of Ports)";E={[string]::Join(",",( $_ | Get-VirtualSwitch | %{$_.Name + "(" + $_.NumPorts + ")"}))}},
    	@{N="Portgroups";E={[string]::Join(",",( $_ | Get-VirtualPortGroup | %{$_.Name}))}}
    

    ____________

    Blog: LucD notes

    Twitter: lucd22



  • 45.  RE: Need a powershell script for collecting ESX host information

    Posted Jun 21, 2010 03:52 AM

    Luc,

    Can you please add 2 fields to this script as given below,

    pNIC MAC --> Mac address of the Physical Nics in the ESX box seperated by commas.

    SC Mem --> Service console memory allocated to the ESX host



  • 46.  RE: Need a powershell script for collecting ESX host information

    Posted Jun 21, 2010 07:00 AM

    There you go

    Get-VMHost | Select Name, Version,
    	Build, 
    	@{N="Cluster Name";E={($_ | Get-Cluster).Name}},
    	Manufacturer, Model, ProcessorType,
    	@{N="NumCPU";E={($_| Get-View).Hardware.CpuInfo.NumCpuPackages}},
    	@{N="Cores";E={($_| Get-View).Hardware.CpuInfo.NumCpuCores}},
    	@{N="Service Console IP";E={($_|Get-VMHostNetwork).ConsoleNic[0].IP}},
    	@{N="vMotion IP";E={($_|Get-VMHostNetwork).VirtualNic[0].IP}},
    	@{N="HBA count";E={($_| Get-VMHostHba | where {$_.Type -eq "FibreChannel"}).Count}},
    	@{N="DatastoreName(Capacity in GB)";E={[string]::Join(",",( $_ | Get-Datastore | %{$_.Name + "(" + ("{0:f1}" -f ($_.CapacityMB/1KB)) + ")"}))}},
    	@{N="FC Device";E={[string]::Join(",",(($_ | Get-View).Config.StorageDevice.HostBusAdapter | where{$_.GetType().Name -eq "HostFibreChannelHba"} | %{$_.Device}))}},
    	@{N="FC WWN";E={[string]::Join(",",(($_ | Get-View).Config.StorageDevice.HostBusAdapter | where{$_.GetType().Name -eq "HostFibreChannelHba"} | %{"{0:x}" -f $_.NodeWorldWideName}))}},
    	@{N="Physical NICS count";E={($_ | Get-View).Config.Network.Pnic.Count}},
    	@{N="vSwitches(Number of Ports)";E={[string]::Join(",",( $_ | Get-VirtualSwitch | %{$_.Name + "(" + $_.NumPorts + ")"}))}},
    	@{N="Portgroups";E={[string]::Join(",",( $_ | Get-VirtualPortGroup | %{$_.Name}))}},
    	@{N="pNIC MAC";E={[string]::Join(",",($_ | Get-VMHostNetworkAdapter | %{$_.MAC}))}},
    	@{N="SC Mem (MB)";E={"{0:f1}" -f (($_| Get-View).Config.ConsoleReservation.ServiceConsoleReserved/1MB)}}
    

    ____________

    Blog: LucD notes

    Twitter: lucd22



  • 47.  RE: Need a powershell script for collecting ESX host information

    Posted Jun 21, 2010 01:51 PM

    Luc,

    Can you please add 2 fields to this script as given below,

    vKernel Vlan ID :

    Service Console Vlan ID:

    Thanks



  • 48.  RE: Need a powershell script for collecting ESX host information

    Posted Jun 23, 2010 05:03 AM

    Thanks Luc.

    I also added the ESX UUID to the script with the below line of code

    @{N="UUID";E={($_| Get-View).summary.hardware.uuid}}
    



  • 49.  RE: Need a powershell script for collecting ESX host information

    Posted Jun 29, 2010 02:32 PM

    Hi,

    Can anyone help me out in finding Vlan ID of Service Console & VMkernel.

    Thanks in Advance :smileyblush:

    Pranab



  • 50.  RE: Need a powershell script for collecting ESX host information

    Posted Jun 30, 2010 09:51 AM

    To find the Vlan ID of the Service Console and VMkernel of all hosts you can use the next script:

    Get-VMHost | Sort-Object -property Name | `
      ForEach-Object {
        $VMHost = $_
          $VMHost | Get-VirtualPortGroup | `
            Select-Object -Property @{N="VMHost";E={$VMHost.Name}},@{N="VirtualPortGroup";E={$_.Name}},VlanId | `
            Where-Object {$_.VirtualPortGroup -eq "Service Console" -or $_.VirtualPortGroup -eq "VMkernel"}
      }
    

    Regards, Robert



  • 51.  RE: Need a powershell script for collecting ESX host information

    Posted Jun 30, 2010 02:54 PM

    Hey Robert Thanks for the script, Can we integrate this script with LUCs script? My requirement is one script.

    Pranab



  • 52.  RE: Need a powershell script for collecting ESX host information

    Posted Jul 01, 2010 08:02 AM

    Hi Pranab,

    here you get Luc's and my script integrated:

    Get-VMHost | Select Name, Version,
    	Build, 
    	@{N="Cluster Name";E={($_ | Get-Cluster).Name}},
    	Manufacturer, Model, ProcessorType,
    	@{N="NumCPU";E={($_| Get-View).Hardware.CpuInfo.NumCpuPackages}},
    	@{N="Cores";E={($_| Get-View).Hardware.CpuInfo.NumCpuCores}},
    	@{N="Service Console IP";E={($_|Get-VMHostNetwork).ConsoleNic[0].IP}},
    	@{N="vMotion IP";E={($_|Get-VMHostNetwork).VirtualNic[0].IP}},
    	@{N="HBA count";E={($_| Get-VMHostHba | where {$_.Type -eq "FibreChannel"}).Count}},
    	@{N="DatastoreName(Capacity in GB)";E={[string]::Join(",",( $_ | Get-Datastore | %{$_.Name + "(" + ("{0:f1}" -f ($_.CapacityMB/1KB)) + ")"}))}},
    	@{N="FC Device";E={[string]::Join(",",(($_ | Get-View).Config.StorageDevice.HostBusAdapter | where{$_.GetType().Name -eq "HostFibreChannelHba"} | %{$_.Device}))}},
    	@{N="FC WWN";E={[string]::Join(",",(($_ | Get-View).Config.StorageDevice.HostBusAdapter | where{$_.GetType().Name -eq "HostFibreChannelHba"} | %{"{0:x}" -f $_.NodeWorldWideName}))}},
    	@{N="Physical NICS count";E={($_ | Get-View).Config.Network.Pnic.Count}},
    	@{N="vSwitches(Number of Ports)";E={[string]::Join(",",( $_ | Get-VirtualSwitch | %{$_.Name + "(" + $_.NumPorts + ")"}))}},
    	@{N="Portgroups";E={[string]::Join(",",( $_ | Get-VirtualPortGroup | %{$_.Name}))}},
    	@{N="pNIC MAC";E={[string]::Join(",",($_ | Get-VMHostNetworkAdapter | %{$_.MAC}))}},
    	@{N="SC Mem (MB)";E={"{0:f1}" -f (($_| Get-View).Config.ConsoleReservation.ServiceConsoleReserved/1MB)}},
    	@{N="SC VlanId";E={($_| Get-VirtualPortGroup | Where-Object {$_.Name -eq "Service Console"}).VlanId}},
    	@{N="VMKernel VlanId";E={($_| Get-VirtualPortGroup | Where-Object {$_.Name -eq "VMkernel"}).VlanId}}
    



  • 53.  RE: Need a powershell script for collecting ESX host information

    Posted Jul 01, 2010 03:22 PM

    Hi Robert,

    Thanks for help, Really Appreciate it.

    Pranab



  • 54.  RE: Need a powershell script for collecting ESX host information

    Posted Dec 02, 2010 05:35 PM

    I only need the WWN for the HBA adapters. I changed the triggers as follows.

    Get-VMHost | Select Name, Version,

    Build,

    @{N="Cluster Name";E={($_ | Get-Cluster).Name}},

    Manufacturer, Model, ProcessorType,

    @{N="HBA count";E={($_| Get-VMHostHba | where {$_.Type -eq "FibreChannel"}).Count}},

    @{N="FC Device";E={[string]::Join(",",(($_ | Get-View).Config.StorageDevice.HostBusAdapter | where{$_.GetType().Name -eq "HostFibreChannelHba"} | %{$_.Device}))}},

    @{N="FC WWN";E={[string]::Join(",",(($_ | Get-View).Config.StorageDevice.HostBusAdapter | where{$_.GetType().Name -eq "HostFibreChannelHba"} | %{"{0:x}" -f $_.NodeWorldWideName}))}},

    @{N="IScsi HBA Name";E={[string]::Join(",",(($_| Get-View).Config.StorageDevice.HostBusAdapter | where {$_.GetType().Name -eq "HostInternetScsiHba"} | %{$_.Device}))}},

    @{N="IScsi IP addr";E={[string]::Join(",",(($_| Get-View).Config.StorageDevice.HostBusAdapter | where {$_.GetType().Name -eq "HostInternetScsiHba"} | %{$_.ipProperties.address}))}}

    However the output only shows me the following below. In the Client is see 4 HBA names. See attached picture.

    Name : XXXXXXXX

    Version : 4.1.0

    Build : 260247

    Cluster Name : E3 - Production Cluster

    Manufacturer : HP

    Model : ProLiant BL680c G5

    ProcessorType : Intel(R) Xeon(R) CPU E7330 @ 2.40GHz

    HBA count : 2

    FC Device : vmhba1,vmhba2

    FC WWN : 5001438002218bd9,5001438002218bdb



  • 55.  RE: Need a powershell script for collecting ESX host information

    Posted Dec 02, 2010 06:34 PM

    You want the PortWorldWideName property instead of the NodeWorldWideName property.

    ____________

    Blog: LucD notes

    Twitter: lucd22



  • 56.  RE: Need a powershell script for collecting ESX host information

    Posted Dec 02, 2010 07:07 PM

    Modified.

    Get-VMHost | Select Name, Version,

    @{N="HBA count";E={($_| Get-VMHostHba | where {$_.Type -eq "FibreChannel"}).Count}},

    @{N="FC Device";E={string::Join(",",(($_ | Get-View).Config.StorageDevice.HostBusAdapter | where{$_.GetType().Name -eq "HostFibreChannelHba"} | %{$_.Device}))}},

    @{N="FC WWN";E={string::Join(",",(($_ | Get-View).Config.StorageDevice.HostBusAdapter | where{$_.GetType().Name -eq "HostFibreChannelHba"} | %{"{0:x}" -f $_.PortWorldWideName}))}}

    However I now get the following output showing no details.

    Name : epqvh306.XXXXXXXXXX

    Version : 4.1.0

    HBA count : 2

    FC Device :

    FC WWN :



  • 57.  RE: Need a powershell script for collecting ESX host information

    Posted Dec 02, 2010 08:02 PM

    That's most probably because the square brackets were eaten by the forum SW.

    I attached the script.

    ____________

    Blog: LucD notes

    Twitter: lucd22



  • 58.  RE: Need a powershell script for collecting ESX host information

    Posted Jul 20, 2011 06:11 PM

    hi Luc,

    i combined most of the variants requested in this thread into a single file and appended Export-CSV at the end since I have more than 25 servers to get an inventory, however when running in PowerCLI 4.1.0U1 there were couple of obsolete parameters which I changed based on the info that was printed on the command line however now it doesn't get me the console IP and vmkernel IP..

    Also is there a way to split the datastores and pnic's into multiple lines so that when Export-CSV works the resulting output is more readable than the way it currently has the enstries exported?

    any help is highly appreciated.

    I have attached the script so other's can also use it.

    Note: I should have mentioned the new network adapter cmdlet is call Get-VMHostNetworkAdapter

    http://www.vmware.com/support/developer/PowerCLI/PowerCLI41U1/html/Get-VMHostNetworkAdapter.html

    Message was edited by: pmeqix (to include the new network adapter cmdlet info)



  • 59.  RE: Need a powershell script for collecting ESX host information

    Posted Jul 20, 2011 07:22 PM

    To get the console and vmkernel IP with the Get-VMHostNetworkAdapter cmdlet, change those 2 lines as follows.

    @{N="Service Console IP";E={($_|Get-VMHostNetworkAdapter -Name vmk0).IP}},
    @{N="vMotion IP";E={($_|Get-VMHostNetworkAdapter -Name vswif0).IP}},

    To split the datastore and pnic info over multiple lines, would mean that you have to repeat all the other properties each time.

    It would make the CSV much longer and more difficult to read imho.



  • 60.  RE: Need a powershell script for collecting ESX host information

    Posted Jul 21, 2011 05:33 AM

    LucD

    Thanks for the prompt response and the update.

    For anyone else who would like to use I have attached the updated script.

    Note: This script currently does not still capture service console IP if your ESX host is running some old ESX 4.0 builds which do not use vmk0 for service console.

    Message was edited by: pmeqix - To provide cavear on the shortcomings of the script



  • 61.  RE: Need a powershell script for collecting ESX host information

    Posted Jul 21, 2011 10:29 AM

    Hi

    Brilliant work guys

    Cheers

    Artur



  • 62.  RE: Need a powershell script for collecting ESX host information

    Posted May 16, 2013 10:09 PM

    Hi Luc

    Is there a way that you can include the cluster name in this report?

    Thanks



  • 63.  RE: Need a powershell script for collecting ESX host information

    Posted Mar 29, 2010 08:41 AM

    Hi,

    You can also try below code snippet.

    Connect-VIServer <server> -User <user> -Password <password>
    $HostReport = @()
    Get-VMHost |Get-View |%{	
    	$Report = "" | select Hostname, version, Build, manufacture, Model,cpu_model, core_num, ip_address,vmotion_ip, HBA_num, P_nic
    	$Report.Hostname = $_.Name 
    	$Report.version =$_.Config.Product.Version 
    	$Report.Build =$_.Config.Product.Build 
    	$Report.manufacture =$_.Hardware.SystemInfo.Vendor 
    	$Report.Model =$_.Hardware.SystemInfo.Model 
    	$Report.cpu_model =$_.Summary.Hardware.CpuModel 
    	$Report.core_num =$_.Hardware.CpuInfo.NumCpuCores 
    	$Report.ip_address =$_.Config.Network.ConsoleVnic[0].Spec.ip.ipaddress 
    	$Report.vmotion_ip =$_.Config.Vmotion.IpConfig.IpAddress
    	$Report.HBA_num =$_.Summary.Hardware.NumHBAs
    	$Report.P_nic =$_.Config.Network.Pnic.count 
    	$HostReport += $Report
    } 
    $HostReport | Export-Csv "C:\HostReport.csv" -NoTypeInformation
    



  • 64.  RE: Need a powershell script for collecting ESX host information

    Posted Mar 31, 2010 03:50 AM

    hi Jeevenj,

    i get this error while running your script. Cannot index into a null array. At :line:12 char:51 + $Report.ip_address =$_.Config.Network.ConsoleVnic[0].Spec.ip.ipaddress



  • 65.  RE: Need a powershell script for collecting ESX host information

    Posted Mar 31, 2010 04:57 AM

    Try this

    Connect-VIServer <server> -User <user> -Password <password>
    $HostReport = @()
    Get-VMHost |Get-View |%{	
    	$Report = "" | select Hostname, version, Build, manufacture, Model,cpu_model, core_num, ip_address,vmotion_ip, HBA_num, P_nic
    	$Report.Hostname = $_.Name 
    	$Report.version =$_.Config.Product.Version 
    	$Report.Build =$_.Config.Product.Build 
    	$Report.manufacture =$_.Hardware.SystemInfo.Vendor 
    	$Report.Model =$_.Hardware.SystemInfo.Model 
    	$Report.cpu_model =$_.Summary.Hardware.CpuModel 
    	$Report.core_num =$_.Hardware.CpuInfo.NumCpuCores 
    	if($Report.version -like "3.5.*"){
    		$Report.ip_address =$_.Config.Network.ConsoleVnic.Spec.ip.ipaddress 
    	}
    	else {$Report.ip_address =$_.Config.Network.ConsoleVnic[0].Spec.ip.ipaddress}
    	$Report.vmotion_ip =$_.Config.Vmotion.IpConfig.IpAddress
    	$Report.HBA_num =$_.Summary.Hardware.NumHBAs
    	$Report.P_nic =$_.Config.Network.Pnic.count 
    	$HostReport += $Report
    } 
    $HostReport | Export-Csv "C:\HostReport.csv" –NoTypeInformation
    

    Let me know if you find any empty parameter.



  • 66.  RE: Need a powershell script for collecting ESX host information

    Posted Sep 23, 2011 06:06 AM

    Hi Jeevenj,

    Can you please also add CPU, Mem Utilisaiton, and ESX sensors data.

    Thanks in advance

    -Mithilesh



  • 67.  RE: Need a powershell script for collecting ESX host information

    Posted May 13, 2010 04:17 PM

    Using the info from LucD and jeveenj's posts, I mashed the following script to collect data from our multiple Vcenter instances, report includes info for socket and core count:

    _________________________________________

    $viservers = "vcenter1","vcenter2","vcenter3","vcenter4"

    foreach ($singleViserver in $viservers)

    {

    Connect-VIServer $singleViserver

    $HostReport = @()

    Get-VMHost |Get-View |%{

    $Report = "" | select Hostname, version, Build, manufacture, Model,cpu_model, cpu_num, core_num, ip_address,vmotion_ip, HBA_num, P_nic

    $Report.Hostname = $_.Name

    $Report.version =$_.Config.Product.Version

    $Report.Build =$_.Config.Product.Build

    $Report.manufacture =$_.Hardware.SystemInfo.Vendor

    $Report.Model =$_.Hardware.SystemInfo.Model

    $Report.cpu_model =$_.Summary.Hardware.CpuModel

    $Report.cpu_num =$_.Hardware.CpuInfo.NumCpuPackages

    $Report.core_num =$_.Hardware.CpuInfo.NumCpuCores

    if($Report.version -like "3.5.*"){

    $Report.ip_address =$_.Config.Network.ConsoleVnic.Spec.ip.ipaddress

    }

    else {$Report.ip_address =$_.Config.Network.ConsoleVnic[0].Spec.ip.ipaddress}

    $Report.vmotion_ip =$_.Config.Vmotion.IpConfig.IpAddress

    $Report.HBA_num =$_.Summary.Hardware.NumHBAs

    $Report.P_nic =$_.Config.Network.Pnic.count

    $HostReport += $Report

    }

    }

    $HostReport | Export-Csv ".\Full-HostReport.csv" –NoTypeInformation

    _________________________________________

    Thought someone else may look for this exact code since I was looking for it. As noted, it requires the latest version of PowerCli

    Good work LucD and jeveenj!!

    Ty Lopes



  • 68.  RE: Need a powershell script for collecting ESX host information

    Posted Sep 02, 2010 10:21 AM

    Hi all,How the get - the serial num of the hardware ? - the runtime ? Thanks

    ML 
    
    
    
    



  • 69.  RE: Need a powershell script for collecting ESX host information

    Posted Sep 02, 2010 01:21 PM

    I don't know how to get the ESX server serial number through the vSphere API, but you can get it using plink.exe:

    $User = "root"
    $Password = "password"
    $Command = 'esxcfg-info'
    
    function Invoke-VMhostCommand {
      # This function assumes that plink.exe is in your path
      param([parameter(Mandatory=$true)][string] $VMHost,
            [parameter(Mandatory=$true)][string] $User,
            [parameter(Mandatory=$true)][string] $Password,
            [parameter(Mandatory=$true)][string] $Command)
    
      $plink = "plink.exe"
      $plinkoptions = " -v -batch -pw $Password"
      $remoteCommand = '"' + $Command + '"'
      $PlinkCommand = $plink + " " + $plinkoptions + " " + $User + "@" + $VMHost + " " + $remoteCommand
      $msg = Invoke-Expression -command $PlinkCommand
      $Report = "" | Select-Object Host,Output
      $Report.Host = $VMHost
      $Report.Output = $msg
      $Report
    }
    
    $Report = Get-VMHost | ForEach-Object {Invoke-VMHostCommand -VMHost $_.Name -User $User -Password $Password -Command $Command }
    $Report | ForEach-Object { $_.Output = $_.Output | Select-String -pattern "Serial N" -casesensitive } 
    $Report | Format-Table -AutoSize
    

    Regards, Robert