rbmadison
Contributor
Contributor

get-vm Help

I'm not that familiar with powershell. I've used vbscript quite a lot however. Can someone tell me how I can run the Get-vm and then run an external process on each VM name returned? Any examples would be greatly appreciated.

Thanks

0 Kudos
6 Replies
halr9000
Commander
Commander

If your vm name is equal to the hostname and is resolvable by DNS then it should be really easy. If not, it depends on some other factors maybe. What is it that you want to do on each system?

get-vm | foreach-object {
  # $_ is an automatic variable representing the object currently in the pipeline
  write-output "$_.name `t $( (Get-WmiObject Win32_BaseBoard).serialnumber )"
}

This would query WMI (only for windows systems obviously) to find the hardware serial # for each VM, assuming it was a valid computername. Output would look similar to this:

ATLLAPHROTTENBE .7B530C1.CN1296169KB591.

Hal Rottenberg

Co-Host, PowerScripting Podcast (http://powerscripting.net)

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
0 Kudos
halr9000
Commander
Commander

I almost forgot, you can get the IP address if the VM Tools are running.

get-vm | % { # % is alias for foreach-object
  $_.Guest.IPAddress
}

Hal Rottenberg

Co-Host, PowerScripting Podcast (http://powerscripting.net)

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
0 Kudos
rbmadison
Contributor
Contributor

I want to run a vcb backup of selected VMs. Some of which will not have an IP or may not be powered on. I need the VM name to run the VCBMounter command. How also would I run an external command like VCBMounter.exe?

Thanks

0 Kudos
halr9000
Commander
Commander

It may be as easy as this:

get-vm | foreach-object { VCBMounter $_.Name }

However, if you have spaces or parenthesis or square brackets in any of the VM names, it'll get a little more complicated.

Hal Rottenberg

Co-Host, PowerScripting Podcast (http://powerscripting.net)

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
0 Kudos
rbmadison
Contributor
Contributor

I am still having problems doing this and was wondering if anyone had a better method or would know how I could do backup all of our VMs via script? I want to use the backup proxy server and not anything that runs on the ESX servers itself. Any examples in powershell or other methods would be appreciated.

Thanks!

0 Kudos
halr9000
Commander
Commander

Sounds like your question is not specific to PowerShell. I personally have not used the VCBstuff so I won't be of much use. If nobody else speaks up, you may want to search/post to other areas of VMware's forums, and then come back here when you know more specifically what it is that you want to do. Then we can definitely help you get the most out of it using powershell and the vi-toolkit.

Hal Rottenberg

Co-Host, PowerScripting Podcast (http://powerscripting.net)

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
0 Kudos