3 Replies Latest reply on Aug 9, 2019 2:33 PM by LucD

    script getting multiple lines of same vm

    tdubb123 Master

      for this script, I am trying to get some info on vms. Name, DC, Cluster.

       

      But why am I getting multiple same lines of same VM?

       

       

      $report = @()

      foreach ($dc in Get-Datacenter) {

          foreach ($cluster in Get-Cluster -Location $dc){

            $vms = get-content "c:\scripts\vms.txt

            foreach ($vm in $vms){

              $info = "" | select Name, Datacenter, Cluster

              $info.Name = $vm.name

              $info.datacenter = $dc.name

              $info.cluster = $cluster.name

              $info.vcenter = $cluster.Uid.Split(":")[0].Split("@")[1]

              $report += $info

            }

          }

      }

      $report | out-gridview