March 15th, 2014

PowerTip: PowerShell One-Liner to Find Virtual Machine

Doctor Scripto
Scripter

Summary: Use Windows PowerShell 4.0 to find a virtual machine.

Hey, Scripting Guy! Question How can I use Windows PowerShell 4.0 to find a virtual machine when I only have partial name information so I can stop it or make other changes as required?

Hey, Scripting Guy! Answer Use the Get-VM cmdlet to return virtual machine objects, use the dotted Where, and filter with a script block.
          Add the name property, and use a regular expression (or wild card) to match the virtual machine
          that you are interested in. The following command finds a virtual machine with a name that begins with c1:

(get-vm).Where{$_.name -match '^c1'}

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.

Feedback