hi
any difference between these 2 reporting formats?
connect-viserver vc
$Report = "" | select Hostname, version, powerstate, OSVersion
$Report.Hostname = $vmhost.Name
$Report.version = $vmhost.Config.Product.version
$Report.powerstate = $vmhost.Runtime.PowerState
$Report.OSversion = $vmhost.Config.Product.FullName
}
$HostReport
----------------------------------------------------------------------------------------
connect-viserver vc
$vmhost = $_
$Report = "" | select Hostname, version, powerstate, OSVersion
$Report.Hostname = $vmhost.Name
$Report.version = $vmhost.Config.Product.version
$Report.powerstate = $vmhost.Runtime.PowerState
$Report.OSversion = $vmhost.Config.Product.FullName
}
$HostReport
why define an empty array on the second one for?
I think I answered that earlier.
See "Because you want to use the addition (+=) of a row to the report array."
If you wouldn't declare the array, the addition of the object $Report to the variable $HostReport would not work.
Defining $HostReport as an [array] provides the addition of an object to the array.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Because you want to use the addition (+=) of a row to the report array.
Not sure how the 1st one is producing output ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
lucd
both gives same output.
Strange, in the 1st script you are collecting the data in $Report but you are displaying $HostReport.
Since you don't seem to assign anything to $HostReport, there should be no output.
Could it be that $HostReport is still populated from the 2nd script.
You don't declare $HostReport as an array in the 1st script
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
sorry there was typo error. but both gives same output
=======================================================
Get-VMHost | Get-View | % {
$vmhost = $_
$Report = "" | select Hostname, version, powerstate, OSVersion
$Report.Hostname = $vmhost.Name
$Report.version = $vmhost.Config.Product.version
$Report.powerstate = $vmhost.Runtime.PowerState
$Report.OSversion = $vmhost.Config.Product.FullName
$Report
}
========================================================
output
Hostname : esxhost1.domain.com
version : 6.0.0
powerstate : poweredOn
OSVersion : VMware ESXi 6.0.0 build-2494585
Hostname : esxhost2.domain.com
version : 6.0.0
powerstate : poweredOn
OSVersion : VMware ESXi 6.0.0 build-2494585
========================================================
$HostReport = @()
$vmhost = $_
$Report = "" | select Hostname, version, powerstate, OSVersion
$Report.Hostname = $vmhost.Name
$Report.version = $vmhost.Config.Product.version
$Report.powerstate = $vmhost.Runtime.PowerState
$Report.OSversion = $vmhost.Config.Product.FullName
}
$HostReport
=======================================================
Hostname : esxhost1.domain.com
version : 6.0.0
powerstate : poweredOn
OSVersion : VMware ESXi 6.0.0 build-2494585
Hostname : esxhost2.domain.com
version : 6.0.0
powerstate : poweredOn
OSVersion : VMware ESXi 6.0.0 build-2494585
Ok, got it.
And I suppose your question regarding the empty array declaration is answered as well ? Or not ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
lucd, i guess question is why do we need the array defined in the 2nd script
if the 1st script gives same output
If you just want a dump in the order returned by Get-VMHost then you don't need the collection (array). You'd want the collection if you plan on doing something else with the data besides just dumping it to the screen "as is" (i.e. if you wanted a report that dumped out the hosts sorted by version number and a count of how many for each version where powered on and powered off)
I think I answered that earlier.
See "Because you want to use the addition (+=) of a row to the report array."
If you wouldn't declare the array, the addition of the object $Report to the variable $HostReport would not work.
Defining $HostReport as an [array] provides the addition of an object to the array.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thanks that makes sense