<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Having trouble with foreach loops in VMware PowerCLI Discussions</title>
    <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Having-trouble-with-foreach-loops/m-p/448171#M10195</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why don't you just this simple one liner and be done with it?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Get-VMHostHardware&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;The default output will give you the Hostname, Manufacturer, Model, Serial Number, etc and you can tweak it to your needs.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You got to be at least on PowerCLI 6.0 R2 I for this to work.&lt;/P&gt;&lt;P&gt;&lt;A href="https://blogs.vmware.com/PowerCLI/2016/01/audit-and-manage-esxi-hosts-with-powercli.html" style="font-size: 10pt;" title="https://blogs.vmware.com/PowerCLI/2016/01/audit-and-manage-esxi-hosts-with-powercli.html"&gt;Audit and Manage ESXi Hosts with PowerCLI - VMware PowerCLI Blog - VMware Blogs&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I personally run the PowerCLI in the latest version 6.5 Release 1 and it works like a charme.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just type in "Get-Help Get-VMHostHardware" to get some basic explanation and command examples, &lt;SPAN style="font-size: 10pt;"&gt;or just go directly to the online-help:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.vmware.com/support/developer/PowerCLI/PowerCLI65R1/html/Get-VMHostHardware.html" title="https://www.vmware.com/support/developer/PowerCLI/PowerCLI65R1/html/Get-VMHostHardware.html"&gt;Get-VMHostHardware - PowerCLI VMware.VimAutomation.Core Help Reference&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 10 Feb 2017 20:19:32 GMT</pubDate>
    <dc:creator>DaHess_DNVGL</dc:creator>
    <dc:date>2017-02-10T20:19:32Z</dc:date>
    <item>
      <title>Having trouble with foreach loops</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Having-trouble-with-foreach-loops/m-p/448168#M10192</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;After a great deal of research, failed prototypes, and an excess of caffeine and nicotine, I found the commands I needed for pulling the 'ServiceTag' / 'SerialNumber' from my ESXi hosts in vSphere 5.0 - 5.5.&amp;nbsp; As an example:&lt;/P&gt;&lt;P&gt;$esxcli = Get-Esxcli -VMHost &amp;lt;host name&amp;gt; -V2&lt;/P&gt;&lt;P&gt;$esxcli.hardware.platform.get.Invoke().SerialNumber&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This formula makes up the script for getting that tag/serial number for that one host.&amp;nbsp; I must be brain dead today because I'm traveling in a few hours by car for about 3 hours - very mind numbing without music.&amp;nbsp; I can't seem to figure out the correct way to set it up to so that I get that information from each of the hosts in a vCenter.&amp;nbsp; For this exercise, I have 19 hosts, all UCS created, but they have their own tag as well.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can anyone guide me towards the proper syntax for a foreach loop to perform my little script above?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance as always&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Feb 2017 13:23:46 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Having-trouble-with-foreach-loops/m-p/448168#M10192</guid>
      <dc:creator>miguelvelezwhit</dc:creator>
      <dc:date>2017-02-10T13:23:46Z</dc:date>
    </item>
    <item>
      <title>Re: Having trouble with foreach loops</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Having-trouble-with-foreach-loops/m-p/448169#M10193</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Are you talking something like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Once connected to your vCenter&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="xml" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14867337971274125" jivemacro_uid="_14867337971274125"&gt;
&lt;P&gt;$allHosts = get-vmHost&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;foreach ($vmhost in $allHosts( {&lt;/P&gt;
&lt;P&gt;&amp;nbsp; write-host "Running ESXCLIv2 on host $vmhost"&lt;/P&gt;
&lt;P&gt;&amp;nbsp; $esxcli = Get-Esxcli -VMHost $vmhost -V2&lt;/P&gt;
&lt;P&gt;&amp;nbsp; $serialNum = $esxcli.hardware.platform.get.Invoke().SerialNumber&lt;/P&gt;
&lt;P&gt;&amp;nbsp; #Do something with the serial Number here?&lt;/P&gt;
&lt;P&gt;&amp;nbsp; write-host $serialNum&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;or am I missing something?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Feb 2017 13:35:40 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Having-trouble-with-foreach-loops/m-p/448169#M10193</guid>
      <dc:creator>jpsider</dc:creator>
      <dc:date>2017-02-10T13:35:40Z</dc:date>
    </item>
    <item>
      <title>Re: Having trouble with foreach loops</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Having-trouble-with-foreach-loops/m-p/448170#M10194</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is why I love VMware Communities.&amp;nbsp; If I don't have the answer, there are a whole lot of fellow VMware enthusiasts/evangelists like myself who will have the correct answer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks jpsider!!&amp;nbsp; I believe that's going to be the answer for my problem.&amp;nbsp; I'll code it in as soon as I get my first cup of coffee for the day.&amp;nbsp; Perhaps then, I'll be coherent and cognitive enough to test this and let you know the results.&amp;nbsp; Everything looks great, now I have to plug it in and include a statement which provides the name, vmhostname, manufacturer, model and of course serial number.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'll let you know the results - if I do it wrong, I hope you can guide me where I misstepped.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Feb 2017 13:54:43 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Having-trouble-with-foreach-loops/m-p/448170#M10194</guid>
      <dc:creator>miguelvelezwhit</dc:creator>
      <dc:date>2017-02-10T13:54:43Z</dc:date>
    </item>
    <item>
      <title>Re: Having trouble with foreach loops</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Having-trouble-with-foreach-loops/m-p/448171#M10195</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why don't you just this simple one liner and be done with it?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Get-VMHostHardware&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;The default output will give you the Hostname, Manufacturer, Model, Serial Number, etc and you can tweak it to your needs.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You got to be at least on PowerCLI 6.0 R2 I for this to work.&lt;/P&gt;&lt;P&gt;&lt;A href="https://blogs.vmware.com/PowerCLI/2016/01/audit-and-manage-esxi-hosts-with-powercli.html" style="font-size: 10pt;" title="https://blogs.vmware.com/PowerCLI/2016/01/audit-and-manage-esxi-hosts-with-powercli.html"&gt;Audit and Manage ESXi Hosts with PowerCLI - VMware PowerCLI Blog - VMware Blogs&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I personally run the PowerCLI in the latest version 6.5 Release 1 and it works like a charme.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just type in "Get-Help Get-VMHostHardware" to get some basic explanation and command examples, &lt;SPAN style="font-size: 10pt;"&gt;or just go directly to the online-help:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.vmware.com/support/developer/PowerCLI/PowerCLI65R1/html/Get-VMHostHardware.html" title="https://www.vmware.com/support/developer/PowerCLI/PowerCLI65R1/html/Get-VMHostHardware.html"&gt;Get-VMHostHardware - PowerCLI VMware.VimAutomation.Core Help Reference&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Feb 2017 20:19:32 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Having-trouble-with-foreach-loops/m-p/448171#M10195</guid>
      <dc:creator>DaHess_DNVGL</dc:creator>
      <dc:date>2017-02-10T20:19:32Z</dc:date>
    </item>
    <item>
      <title>Re: Having trouble with foreach loops</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Having-trouble-with-foreach-loops/m-p/448172#M10196</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could also do this with a one-liner.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;DIV style="text-align: Left; font-family: Segoe UI; font-style: normal; font-weight: normal; font-size: 12; color: #000000;"&gt;&lt;P style="font-family: Lucida Console; margin: 0 0 0 0; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 16;"&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;SPAN&gt;Get-VMHost&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #a9a9a9;"&gt;&lt;SPAN&gt;|&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;SPAN&gt;Get-Esxcli&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000080;"&gt;&lt;SPAN&gt;-V2&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #a9a9a9;"&gt;&lt;SPAN&gt;|&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: Lucida Console; margin: 0 0 0 0; background-color: #ffffff;"&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;SPAN&gt;Select&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt; @{N&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #a9a9a9;"&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #8b0000;"&gt;&lt;SPAN&gt;'VMHost'&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;;E&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #a9a9a9;"&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #ff4500;"&gt;&lt;SPAN&gt;$_&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #a9a9a9;"&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;VMHost&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #a9a9a9;"&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;Name}}&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #a9a9a9;"&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: Lucida Console; margin: 0 0 0 0; background-color: #ffffff;"&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @{N&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #a9a9a9;"&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #8b0000;"&gt;&lt;SPAN&gt;'Serial'&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;;E&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #a9a9a9;"&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #ff4500;"&gt;&lt;SPAN&gt;$_&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #a9a9a9;"&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;hardware&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #a9a9a9;"&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;platform&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #a9a9a9;"&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;get&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #a9a9a9;"&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;Invoke()&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #a9a9a9;"&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;SerialNumber}}&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: Lucida Console; margin: 0 0 0 0; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Feb 2017 14:48:22 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Having-trouble-with-foreach-loops/m-p/448172#M10196</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2017-02-11T14:48:22Z</dc:date>
    </item>
  </channel>
</rss>

