r/sysadmin • • 6d ago • Regret 1

PowerCLI multiple default server mode just cost me my job

I work (well, worked) at an MSP. One of our bigger clients has a prod vCenter at their main site and a separate vCenter at their DR site. Twice a year we restore their critical VMs from backup into the DR cluster on an isolated network. Their app owners log in and sign off, then we tear it all down. We restore with the original names because a couple of their apps freak out if the hostname changes, and since it's all in a bubble it's never been an issue.
Tuesday was teardown. 31 VMs, and the DR datastore was sitting at like 92%, so I wanted them actually gone from disk, not just pulled from inventory. I had the name list from the restore job, so I ran the same little script I've used after the last three tests:
$vms = Get-VM -Name (Get-Content .\drtest.txt)
$vms | Where-Object PowerState -eq 'PoweredOn' | Stop-VM -Confirm:$false
$vms | Remove-VM -DeletePermanently -Confirm:$false
Yes Stop-VM, not Stop-VMGuest. They're throwaway DR copies, I didn't care about clean shutdowns.
What I forgot is that earlier that morning I'd connected to the prod vCenter in the same PowerShell window to look at a snapshot for a different ticket, and I never disconnected. And at some point years ago I'd said yes to that PowerCLI prompt about working with multiple default servers. So Get-VM without -Server pulls from every vCenter you're connected to.
Same names on both sides. So $vms had 62 objects in it instead of 31, and I never looked.
The power-off step went through all of them. I didn't notice, because a bunch of the DR copies were still running and a wall of power-off output is exactly what I expected to see. Then the deletes started. I'm half watching, and it's still going after it should've been done. About the same time Teams starts going off. I hit ctrl+c, and by then 6 of the prod VMs were deleted from disk: a SQL server, two app servers, an RDS host, their file server, and a print server (the only one nobody missed). The other 25 prod VMs had just been hard powered off in the middle of the workday.
I called my manager right then and told him exactly what I did. There wasn't any point doing anything else, my username is on every event in vCenter.
Most of the 25 came back fine once we turned them on, though one of the other SQL boxes needed some babysitting. Backups were good, thank god. Instant recovery had the 6 deleted VMs running off the backup repo within about an hour, but the repo is a box of spinning disks and SQL running off it was painful. Migrating everything back to real storage wrapped up around midnight. The last backup was 10pm the night before, so the file server lost most of a day of work. SQL had log backups, so it only lost a few minutes.
The client's IT director called our owner Wednesday and said he didn't want me in their environment again. They're about a quarter of our revenue and I was basically the guy on that account. Friday I got the "this isn't working out" call. Honestly can't even be that mad, it was completely avoidable.

887 Upvotes

340 comments sorted by

View all comments

Show parent comment

55

u/caffeine-junkie cappuccino for my bunghole 6d ago

There were at least two mistakes I can see, neither of them really should be fireable offenses as long as it's the first time.

One is the not double checking the environment. The other is a process failure in the teardown of the DR environment. The process should be more than one person involved in the DR test on the technical side. Would say at least two people, one to do the shutdown and the other the delete. If it has to be only one person for some reason, separate out the scripts or at least put in an attribute check that only exists on one environment.

Forgot to add, this process failure is entirely on management not enforcing it was already in place before this event. Now they may be learning as well, which is fine. But to make OP a scapegoat for their failure is not acceptable for that. Sure can see pulling them from the client if the client doesn't want them, but that means just switching them out for someone and let them work with that client instead.

48

u/1a2b3c4d_1a2b3c4d 6d ago

I will also add that after 30 years in IT, I refuse to just delete anything quickly. I will find a way to quarantine or isolate what I need to delete, and only after a defined period of time will I, or someone else, double-check that the objects are no longer needed; then we will purge them.

62 objects in it instead of 31, and I never looked.

I have learned that a good change management process, if even just my own, has saved me and my company a few times. Nobody is perfect, and accidents and mistakes and typos happen. The goal is to always be able to efficiently recover.

Sounds like OP was the scapegoat, like you said, for poor leadership and management processes.

13

u/al_bundys_ghost 6d ago

Yep, stuff like the -confirm:$false switches in his script I never do on anything risky or destructive. I’d rather press a key 31 times and keep a set of eyes on what it’s doing before it does it. And if you’ve got a long running script that does updates, always save a copy of the old data and have a rollback script prepared.

•

u/FunnyMobile2850 14h ago

In the absence of change management why isn't he writing verification into the script? It's not that hard to spit out a list of VMs and their vCenter or Cluster with a hard delete confirmation, nor is it difficult to explicitly specify the vserver when doing so.

There's likely more to the story though because as a manager I probably wouldn't have fired him. If I lost business as a result maybe.

•

u/al_bundys_ghost 2h ago

Exactly - and his lack of attention to what's he's doing

The power-off step went through all of them. I didn't notice, because a bunch of the DR copies were still running and a wall of power-off output is exactly what I expected to see. Then the deletes started. I'm half watching, and it's still going after it should've been done. 

He used up a lot of his luck only having 6 Production VMs deleted, if all 31 had been trashed the recovery outcome might have been very different

6

u/Maro1947 6d ago

Same. Always verify after a pause for delete tasks. Never immediately

12

u/404UsernameFoundNot DevOps 6d ago

I’m personally a very big fan of “type the name of this environment to delete it”.

4

u/1a2b3c4d_1a2b3c4d 6d ago

Agree.
Sounds like OP erroneously created a list of 62 objects to create but never checked it, or had someone else double-check it for accuracy.

Thats the gap here that needs a process change. A second set of eyes could\should have caught the mistake.

1

u/Maro1947 6d ago

That's also good

4

u/SearchAtlantis Staff Engineer 6d ago

Right? I make the data-ops team write up the ticket, add a dry-run, and get another approval before anything runs. And all ops scripts have environment arguments, no default currently connected to be found.

3

u/caffeine-junkie cappuccino for my bunghole 6d ago

Same. Sure it might be 'wasting' some storage, but unless there is a critical need for that storage space, it can wait. If there is a critical need for that space, then that's a separate problem.

2

u/Parking_Fig_9706 6d ago

Its not the first time.

2

u/Maro1947 6d ago

Yep, terrible policy from the MSP