VMware Cloud Community
sysCamel
Contributor
Contributor

Find VM by it's ID

I'm trying to find the name of a VM by it's id. I tried the following but it did return any results. Any thoughts?

Get-VM | Where { $_.Id -eq "VirtualMachine-vm-36780/3000" }

0 Kudos
2 Replies
halr9000
Commander
Commander

Take off the /3000 part.

Also, don't use where-object, the get-vm cmdlet has an Id parameter.

Get-VM -Id VirtualMachine-vm-2277






Author of the upcoming book: Managing VMware Infrastructure with PowerShell

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
bassarchist
Contributor
Contributor

I understand it's generally bad practice to use the where-object when you have a specific value in mind, but if you aren't 100% on the vm id, you should try using the -match switch to use a regular expression.

For example:

Get-VM | Where { $_.Id -match "VirtualMachine-vm-36780.*" }

or something like that 😛

0 Kudos