VMware Cloud Community
tekhie
Contributor
Contributor

Get info for all registered vm's

i have a script that tells me a list of VM's created between 30 and 50 days ago. What i would like to know is how to add code so that it only lists the registered vm's at the time the script is run. It is possible that a vm was created in the specified window but has subsequently been deleted. What would be the best way to achieve this ?

tks

chris

0 Kudos
3 Replies
LucD
Leadership
Leadership

In this thread I included a code snippet that shows how this cna be done.

In short, if you have the VM name you can test with the Get-Vm cmdlet like this

....
# Check if guest $vmName is already registered 
      if((Get-VM $vmName -ea SilentlyContinue) -ne $null){
# The VM is still registered.
         ....
      }
}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
prudhviraj
Contributor
Contributor

hey tekhie i dont knw much abt the script language u used but i can suggest from wat you have said...

since your script list the VMs so why dont you redirect the output to a file and check if the VM is registered in any of your hosts. From shell scripting view i would say collect the VMs list then ssh to each server and check if the VM is registerd there using " vmware-cmd -l | grep <VM name> " command. Write a condition to say Y/N based on command output you should be able to get your list of registered VMs.

I might sound simple but this could be bit complex wen you write a script.... Smiley Wink but hey logic works thats for sure.

0 Kudos
tekhie
Contributor
Contributor

Hi Luc

tks for the info

the problem im having is incorporating this into the existing script. If i specify a vm name that is not registered then it doesnt return any data - as you would expect.

If i specify a vmname that does exist, it still returns the information for all vm's whether registered or not

I guess the correct process is for the script to take all registered vms and then match their names against a vm creation date entry and then return that value if a match - but i cant get it working

LucD <communities-emailer@vmware.com>

13/10/09 12:15

To

Chris SALES/gb/socgen@socgen

cc

Subject

New message: "Get info for all registered vm's"

Chris Sales,

A new message was posted in the thread "Get info for all registered vm's":

http://communities.vmware.com/message/1388257#1388257

Author : LucD

Profile : http://communities.vmware.com/people/LucD

Message:

0 Kudos