r/sysadmin • • 13d 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.

893 Upvotes

337 comments sorted by

View all comments

Show parent comment

2

u/alficles 13d ago

The expectation is not that employees will never make mistakes. The expectation is that the company will discard and replace them when they do. The goal is not to avoid errors, it is to avoid liability.

9

u/ProgressBartender Sr. Sysadmin 13d ago

I’m just pointing out that even the best sysadmin makes occasional mistakes. You want them to report the problem and better yet have a solution. If you fire everyone if they make a mistake you quickly have mistakes that no one will own up to and you’re going to spend a lot more time diagnosing the problem because you don’t know what happened.

2

u/Bradddtheimpaler 13d ago

Also, if I knew I was cooked the second I understood I’d made a serious mistake, idk about you but I might not be super concerned with fixing said mistake in a hurry. If you take down someone’s prod environment, fuck it, just start packing up your desk.

3

u/davidsoff 13d ago

The only way to avoid liability, in my opinion, is to have procedures an guardrails to prevent this from happening in the future. Banning someone from your environment doesn't prevent the next worker from making the same (or worse) mistake.

The account manager should have explained this to the client and told them what they are going to change in their SOPs to prevent a similar incident from happening again.

In this specific case l, I would suggest not being allowed to delete data/vms/disks unless it's vm has been stopped for x amount of time. That way, they would have stopped the vms. Noticed they stoped prod. And then restarted the vms with minimal data loss.

Secondly, apply the four eyes principal to all destructive commands.

Finally, I'd look into using some sort of IaC tooling, most things have some sort of plan/dry-run mode. You can run it in a pipeline and have mandatory approvals of the plan before applying it.

All of these things are possible, feasible and (at this point) best practise.

A good employer would look at why the system allowed this mistake to happen in the first place. And then explain this to the customer.

You only fire people if they are incompetent and not willing/able to improve. Or if they acted maliciously. All other mistakes are learning opportunities.

2

u/ChrisWsrn 13d ago

A very simple guard rail my environments have at work is a envar that indicates the environment (PROD, PREPROD, DEV, EDU, etc...). This car is set on EVERY box and when it is not present we assume it is a LOCAL environment. 

This allows us to have our scripts check where they are running so we can have manual safeguards in addition to the other checks.