How I avoid working with the wrong VM, host, server.

At all costs I avoid typing or having to remember names.  🙂

Most of the work on VMs we do is managed by our ticketing system.  I’ve got a directory “Tickets” and for the ones where I’ll need to work with files there’s a sub-directory “Tickets\ticketnumber”.  Say there’s 15 VMs that need a hard drive size increase.  Those 15 VMs will go in a file “servers_ticketnum_comment.txt” with each VM name on one line.  Then all the operations I do will look like “get-content servers_ticketnum_comment.txt | % { do-something $_ }”

That’s the general prinicple.  Put the names of whatever you’re working on in a text file, CSV file, or variable, and keep reusing it.  You could use a Get-VM filter to select the VMs to work with, “get-vm *servertype*”, but if a new VM gets added with a similar name you could start making changes to the wrong VM(s).

It’s also handy if you need to get back to working on the ticket in a week you don’t have to set anything up, just use the file.  If 2 months later there’s a question about which VMs were modified you can check the file.  (It should be logged in your transcript, too.)  If it’s short term and not ticket work I might just use a variable.  Using CSV is for when, using the above example, each hard drive is getting increased by a different size.  The CSV columns would be “VM,SizeKB”.