ESXi

 View Only
  • 1.  Basic powercli to export VM info & find independant disks?

    Posted May 12, 2014 08:56 AM

    Hi,

    I am trying to two basic powercli working and wonder if I could get some help here

    First thing I am trying to do is basically get a list of all VMs, GuestOS, and IP addresses . I've been trying to use this but cannot get it to work unless I specify 1 vm?

    $Report = @()

    $VMs = Get-VM | Where {$_.PowerState -eq “PoweredOn“}

    ForEach ($VM in $VMs) {

          $VMView = $VM | Get-View

          $VMInfo = {} | Select VMName,OS,IPAddress

          $VMInfo.VMName = $vm.name

          $VMInfo.OS = $vm.Guest.OSFullName

          $VMInfo.IPAddress = $vm.Guest.IPAddress

          $Report += $VMInfo

    }

    $Report = $Report | Sort-Object VMName

    $report | Export-Csv c:\output.csv

    Secondly I am trying to run a powercli script to find all independent disks. I can't find anything which lets me search for that? any help here appreciated

    many thanks



  • 2.  RE: Basic powercli to export VM info & find independant disks?

    Posted May 12, 2014 09:33 AM

    Changed the script a bit to use the $VMView a bit more.

    I'm not sure what you did why you only see 1 VM. But here it works properly, try to describe the exact steps you do and what output you get, might be able to help you better then.

    1)

    $Report = @()

    $VMs = Get-VM | Where {$_.PowerState -eq "PoweredOn"}

    ForEach ($VM in $VMs) {

          $VMView = $VM | Get-View |Select config,summary

          $VMInfo = {} | Select VMName,OS,IPAddress

          $VMInfo.VMName = $VMView.Config.name

          $VMInfo.OS = $VMView.summary.Guest.Guestfullname

          $VMInfo.IPAddress = $VMView.summary.Guest.IpAddress

          $Report += $VMInfo

    }

    $Report = $Report | Sort-Object VMName

    $report | Export-Csv c:\output.csv

    }

    2 ) To find your independent persistent disks or change it to your needs :smileyhappy:

    get-vm | Get-HardDisk | where {$_.Persistence -eq "IndependentPersistent"}



  • 3.  RE: Basic powercli to export VM info & find independant disks?

    Posted May 12, 2014 10:38 AM

    Thankyou. how would I modify the first one to only include a specific cluster?

    Many thanks



  • 4.  RE: Basic powercli to export VM info & find independant disks?
    Best Answer

    Posted May 12, 2014 11:13 AM

    $VMs = get-cluster -name "Cluster001"| Get-VM | Where {$_.PowerState -eq "PoweredOn"}



  • 5.  RE: Basic powercli to export VM info & find independant disks?

    Posted May 12, 2014 12:49 PM

    Thankyou i've been able to export all the info I need.

    Now I need to find some kind of useful training material for Powershell/PowerCLI so I will know these things in future :smileyhappy:



  • 6.  RE: Basic powercli to export VM info & find independant disks?

    Posted May 12, 2014 01:09 PM

    silius,

      I highly suggest reading and posting in the Powercli forum.  It is great for getting questions answered and also getting ideas for scripts that you can use.  There are also some pretty good books out there by posters in that forum.

    VMware vSphere™ PowerCLI