Getting VM's information from VC using power shell instead of RVTools.

Hi Experts.

I was wondering if any of you could help me.
I have 4 VCs each in a completely different environment, but I do have a server that can positively connect to all of them.
From that server, I want to run a PS Script that will connect to each server in turn, and extract the following information to an excel file:
<VM Name, Power Status, total CPUs, used CPU, Total RAM, Used RAM, allocated storage, used storage, Folder Path, Operating system, Client>
The client property is a custom annotation I created to be able to say which VM belongs o which client.
The reason I don't wish to use RVTools is that sometimes when they release an update, they will change the column order whch can mess up some Excel Macros, I'll rewrite them to in a later date, but I'd rather start with this.

Thanks in advance.
LVL 9
David SankovskySenior SysAdminAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Andrew Hancock (VMware vExpert / EE MVE^2)VMware and Virtualization ConsultantCommented:
Have you considered using the VMware Community Group Scripts ?

see here

VMware Community Pack

http://www.virtu-al.net/featured-scripts/vmware-powerpack/
Mohammed KhawajaManager - Infrastructure:  Information TechnologyCommented:
I would write the script to loop through each vCenter and output to Excel.  I should do this for myself as I have about half a dozen VCs.
David SankovskySenior SysAdminAuthor Commented:
I'm afraid most scripts used in the Mware Community Group Scripts are pretty outdated.
The function to export all machines can't read custom annotations from the VC, nor does it list the IP Addresses of each one.
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Is the Client field a annotation attribute or an annotation?
To get all the info, you need to combine several different objects. That is why you won't find something ready-to-use - it is too specific probably.
The following code goes thru several VCs, assuming you need one single authentication for all. It shows both a custom attribute and the annotation text - choose as appropriate.
BTW, "IP address" as stated in http:#a41022773 is not part of your original question. I've included it nevertheless. And added the vCenter name plus the VM host.
foreach ($vCenter in 'vCenter.customer1.com', 'vCenter.customer2.com')  {
  Connect-VIServer $vCenter -user vcAdmin -password vcAdmin
  get-vm | % {
    $vm = $_
    New-Object PsObject -Property @{
      'vCenter' = $vCenter
      'vmHost' = $vm.VMHost
      'VM Name' = $vm.Name
      'Power Status' = $vm.PowerState
      'total CPUs' = $vm.NumCPU
      'used CPU' = '*** no clue ***'
      'Total RAM' = $vm.MemoryMB
      'Used RAM' = '*** no clue ***'
      'allocated storage' = $vm.ProvisionedSpaceGB
      'used storage' = $vm.UsedSpaceGB
      'Folder Path' = '*** no clue ***
      'Operating System' = $vm.Guest.OSFullName
      'Client' = $vm.CustomFields['Client']
      'Description' = $vm.Notes   # or $vm.Description
      'IP address' = $vm.Guest.IPAddress
    }
  }
  Disconnect-VIServer $vCenter -force
}

Open in new window

I've not (yet) found all counters, probably we have to query with get-view for life counters.

Side note: just looking for PowerShell scripts as provided won't really help you mid-term. You need to learn some PS and PowerCLI basics to do at least slight modifications yourself.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
David SankovskySenior SysAdminAuthor Commented:
This is a very good starting point.
I'll do some more digging to get the rest.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.