TL;DR - A sysadmin posted this week about losing his job after a PowerCLI script, written for a disaster-recovery test, deleted virtual machines in production as well as DR. The mechanism is one line of PowerCLI configuration most administrators have set and forgotten: DefaultVIServerMode. When it is set to Multiple, a cmdlet without an explicit -Server runs against every connected vCenter in the session. He had connected to production that morning for a snapshot check and never disconnected, so Get-VM returned both estates, and both estates had VMs with identical names. 889 upvotes and 342 comments later, the useful output is the guardrail list. What you need to do: pin every destructive cmdlet to an explicit server, split credentials per environment, put a confirmation tier in front of anything that deletes, and stop trusting implicit defaults in any multi-target shell, including kubectl contexts, AWS profiles and Azure subscriptions.
By The Numbers
| Figure | Value |
|---|---|
| r/sysadmin post score | 889 upvotes |
| Comments on the thread | 342 |
| Client share of his employer's revenue | about 25% |
| Script's history | reused from the last 3 DR tests |
| Values of DefaultVIServerMode | 2 - Single, Multiple |
| Variables PowerCLI keeps for connected servers | 2 - $DefaultVIServer and $DefaultVIServers |
| VMs deleted | production and DR, matched by identical names |
| Time from client complaint to lost position | Wednesday to Friday |
The same numbers in sentences: a mid-sized MSP lost about a quarter of its revenue relationship over an incident that took one cmdlet, a script it had run three times before without harm, and a configuration choice made years earlier and never revisited. The script did not fail. It did exactly what the session told it to do.
I have run scripts against the wrong target. Most people who have automated infrastructure for a living have, usually at a smaller scale and usually with a restore window that saved them. The reason this story landed with 342 comments is not schadenfreude. It is recognition, because the configuration that made it possible is the default any experienced admin sets once and forgets.
The post is titled "PowerCLI multiple default server mode just cost me my job", and the thing that makes it worth reading rather than rubber-necking is that the author does not blame the tool. He calls it a completely preventable mistake and then explains the mechanism precisely enough that the rest of us can check our own sessions. That is a generous thing to do on the way out the door.
The guardrails below are the ones I would want in any environment after reading it. None of them are clever. All of them are habit, which is why the incident happened to somebody who had run the same script three times before.
Let me walk you through what DefaultVIServerMode actually does, how the incident unfolded step by step, why the same landmine is armed in kubectl, AWS profiles and Azure subscriptions, and the specific guardrails I would put in place this week if you run multi-environment automation.
What DefaultVIServerMode actually is
PowerCLI connects to vCenter servers and keeps track of them. Two automatic variables hold that state: $DefaultVIServer is the last server you connected to, and $DefaultVIServers is the array of all servers currently connected in that session.
Then there is a configuration setting that decides what happens when you run a cmdlet and do not tell it which server to use. Set-PowerCLIConfiguration -DefaultVIServerMode controls it, and it has two values.
Single means an untargeted cmdlet runs against $DefaultVIServer, the last one you connected to. Predictable enough, though still implicit.
Multiple means an untargeted cmdlet runs against every server in $DefaultVIServers. This is a deliberate feature. It exists so you can run a read-only inventory across a whole estate in one line, which is genuinely useful. It is also a loaded weapon, because the same behaviour applies to cmdlets that delete things.
The prompt that starts this story is the one PowerCLI shows when you connect to a second server: working with multiple default servers, do you want to set the default mode to Multiple? Answer yes once, years ago, and the setting persists in the user profile. Every future session inherits it. Nothing in a later session reminds you that you chose it.
How the incident unfolded
Here is the sequence as the author describes it, and every step is unremarkable on its own.
Years earlier, he answered Y to the multiple default servers prompt. Standard practice for someone managing several environments from one workstation, and the setting has been in his profile ever since.
That morning, he connected to the client's production vCenter to check snapshots. That is routine work, and it happened to be in the same PowerShell session he would later use for the DR test.
He did not disconnect from production before the DR work began. Why would he? The session was already open, and the DR test was the task in front of him.
He ran the DR test script, the same one used for the last three DR tests, which powered off a set of VMs and deleted them as part of the test scenario. The script calls PowerCLI cmdlets. Those cmdlets did not specify -Server.
Both environments had VMs with identical names, which is normal, because DR environments are built from production. That naming convention is what turned a targeting mistake into a destructive one: the same identifier resolved in both places.
The job ran against both vCenters. Production VMs were powered off and deleted alongside the DR copies. The script reported success, because from its point of view every command completed.
The client's IT director asked that he be removed from the account on Wednesday. The position was gone by Friday. The client was around 25% of that MSP's revenue.
He had already been through the recovery conversation with the client by the time he posted, and the thread's tone is what you would hope for: people checking their own configuration rather than scoring points. Several commenters describe answering that prompt years ago, or not knowing which mode their profile was in.
Why the script was not the problem
The instinct after reading something like this is to audit the script. That is the wrong place to look, and the author says so himself. The script had run three times before. It was tested, in the sense that all three previous runs had produced the expected result.
The failure was in the session state the script inherited: two connected servers, a mode that fans out untargeted cmdlets, and a naming convention that made both environments resolve to the same hostnames. The script was correct in the environment it was written for. The environment it ran in was not the one anybody expected, and nothing in the output said so.
That is the part that makes it a change-control story rather than a scripting story. Change control covers the approval to run the work and the guarantee that the work happens against the target you wrote on the form. Most organisations have the first half.
The same landmine in every multi-target shell
This shape is not VMware-specific. Every tool that keeps a notion of a current target has the same failure mode, and every one of them is one forgotten use command away from a very bad afternoon.
kubectl contexts. kubectl acts on the context that is currently selected. Contexts are named things like prod-apse1 and dr-apse1, and the difference between them is one word you are not reading carefully at 2am. Every serious incident I have heard about with kubectl starts with "the context was still on production".
AWS profiles and accounts. The AWS CLI acts on a profile, and profiles map to accounts. A delete command with the wrong AWS_PROFILE set hits the wrong account and returns success. Cross-account role chains make this worse, because the profile name is often the only clue about where the credentials actually land.
Azure subscriptions. The Entra session holds a current subscription, and az commands default to it. It is common to have three or four subscriptions open in a support session for the same customer, and the CLI will not ask which one you meant.
Terraform workspaces and state files. A workspace is a pointer to a state file, and a state file is the difference between destroying a test VPC and destroying the network your client's phone system runs on.
Docker and SSH contexts. Same idea, lower blast radius, same habit.
The generic rule is that any tool with an implicit current target will eventually run your command against the wrong one. The specific rule is that the blast radius is decided by how much that target can do, which for vCenter, Kubernetes and cloud accounts is a great deal.
Guardrails that would have caught this
These are the controls I would want in place, in order of how much they reduce risk for how little effort. The first three would each have prevented this incident independently.
-
Explicit target on every cmdlet. No exceptions for Get-VM, and none for anything else. If the script says -Server $TargetVC, the session's default mode is irrelevant. This is the single highest-value change and it costs a find-and-replace in your scripts.
-
Force single mode in automation sessions. For unattended scripts, set Set-PowerCLIConfiguration -DefaultVIServerMode Single -Scope Session at the top of the script, so the run cannot fan out. Better still, connect to one server at the start, do the work, and disconnect in a finally block.
-
One environment per session. Do the production snapshot check in its own session, then open a fresh one for the DR test. The reason this simple habit is not universal is that it costs five seconds, and five seconds feels wasteful until the day it is not.
-
Credential segregation per environment. Separate service accounts per vCenter, with permissions that match the environment's role. A DR test account that cannot delete production VMs converts a career-ending mistake into a failed job. This one takes real work, which is why it is the one still missing in most MSPs.
-
Confirmation tiers on destructive cmdlets. Wrap remove, delete and power-off operations in a function that echoes the target server, the object count, the object names and the environment label, then requires a typed confirmation unless a -Force flag is passed deliberately. Two minutes of code per script, and it makes an unattended run fail loudly instead of succeeding quietly.
-
Environment labels in object names or annotations. The identical names were the multiplier here. A DR prefix or a folder structure that says which environment an object belongs to gives a human a chance to notice in the output.
-
Dry run first, always. Most destructive scripts can be run with -WhatIf to prove the target set. If a script cannot be dry run, that is a finding about the script.
-
Log the target line, not just the result. Every script run should print the server, the credential identity and the object count it is about to affect, and log it. The absence of the target in the log is how these incidents get investigated for two days before anyone works out what happened.
-
Change approval that names the target. A change record that says "run DR test script" is not a control. One that says "run test script against dr-vcenter-01 as svc-drtest" gives the approver something to check and the operator something to be held to.
Why this could be good
There is a constructive reading of a 342-comment thread about someone losing their job, and the author offers it himself.
Every commenter who went and checked their DefaultVIServerMode after reading the post is a future incident that did not happen. Several said exactly that. A post-mortem published voluntarily, by the person closest to the mistake, with the mechanism explained precisely and no blame deflected onto the tool, does more to change behaviour in this industry than most security awareness training.
It also clarifies something the vendor documentation does not: which of these settings are dangerous by default. PowerCLI's multiple mode is a legitimate capability. It exists to solve a real problem for people managing large estates. But the point where you tick the box is years before the point where it bites, and no prompt appears at the second moment.
The humbling part is that the author was not careless in an obvious way. He was careful enough to reuse a tested script. The one thing he did not do was close a session, and the tool gave him no signal that it mattered.
Where I am concerned
The default is persistent and invisible. A setting stored in a user profile, chosen years ago, with no reminder at the moment of risk, is a control that has been designed out. If PowerCLI printed the active mode in the banner of every session, half these incidents would stop.
MSP tooling concentrates the risk. A technician with connected sessions to six clients in one terminal is one typo from crossing environments that have no relationship to each other. The multi-tenant model that makes MSP work economically viable is also what makes the blast radius unbounded.
Identical naming is standard practice. DR built from production is correct engineering, and it guarantees that a targeting mistake is a destructive mistake. The naming convention is not the fault, but it is the amplifier, and it deserves a mitigation of its own.
Credential segregation is the control everyone skips. It is the only one on this list that turns a career-ending event into a permissions error, and it is also the one that requires budget, tickets and a change window. Most MSPs run one admin account across every environment because it is faster, and the speed is the risk.
Change control becomes paperwork theatre. An approval that names no target, no credential and no environment is a signature, not a control. The incident here would have passed any approval process that looked like that.
Nobody rehearses the recovery. The technical failure was survivable in principle. What ended the engagement was the client losing confidence, and confidence is decided in the first two hours. The restored VMs and the communication are a separate skill from the deletion.
What to do right now
- Check your mode. Run Get-PowerCLIConfiguration and read DefaultVIServerMode. If it says Multiple, decide whether that is still what you want, and set it to Single with -Scope Session for anything unattended.
- Find the scripts without -Server. Grep your automation for PowerCLI cmdlets that remove, power off, reconfigure or move objects, and confirm each one names its target explicitly.
- Add a guard function that prints server, credential, environment label and object count before any destructive operation, and requires typed confirmation without an explicit force flag.
- Split credentials per environment this quarter. A DR test account with no delete rights on production is the control that turns this from a career event into a failed job.
- One session per environment as a working habit, with a disconnect in the finally block of every script.
- Dry run every destructive script with -WhatIf and read the target set, not just the count.
- Update the change record template so the target environment and credential identity are mandatory fields. If the approver cannot see the target, the approval is not a control.
- Check the equivalents in kubectl, AWS profiles and Azure subscriptions this month. Same question, different command: does this shell know where it is pointing, and would I notice if it was wrong?
- Write the two-hour plan for the day it happens anyway. Who you call, what you restore first, who tells the client. Technical recovery and client confidence are two different recoveries, and only one of them is documented.
Key Takeaways
- DefaultVIServerMode Multiple makes untargeted PowerCLI cmdlets run against every connected vCenter, and the setting persists in the user profile across sessions.
- A script reused from three successful DR tests deleted production VMs once the session also held a production connection.
- Identical object names in production and DR turned a targeting mistake into a destructive one.
- Explicit -Server parameters neutralise the default mode entirely, and cost a find-and-replace.
- The same implicit-target shape exists in kubectl contexts, AWS profiles, Azure subscriptions and Terraform workspaces, so the lesson generalises.
- Credential segregation per environment is the only control that converts a catastrophe into an error message, and it is the one most MSPs skip.
- Approvals that name no target are signatures, not controls. The change record should carry the server, the credential and the environment label.
FAQ
What does PowerCLI's DefaultVIServerMode setting do?
It decides which vCenter an untargeted cmdlet runs against. Single uses the last connected server, Multiple uses every server connected in the session. It is set with Set-PowerCLIConfiguration -DefaultVIServerMode and persists in the user profile.
What is the difference between $DefaultVIServer and $DefaultVIServers?
$DefaultVIServer holds the last server you connected to. $DefaultVIServers holds the array of every server currently connected in that session. In Multiple mode, cmdlets that do not name a server run against the array.
How do I check what mode I am in?
Run Get-PowerCLIConfiguration and read DefaultVIServerMode. It is worth doing on every workstation you automate from, and worth checking inside any script that runs unattended.
Would -Server on every cmdlet have prevented this?
Yes. An explicit -Server overrides the default mode. The script would have acted only on the DR vCenter and the production connection would have been irrelevant.
Is Multiple mode ever useful?
Yes, for read-only work across an estate, like an inventory or a compliance scan across every vCenter you manage. The mode is not the problem. Using it in a session where destructive cmdlets also run is.
Does disconnecting fix it?
Disconnecting removes the server from $DefaultVIServers, so yes, a disconnect before the DR work would have prevented this specific incident. The habit is worth having, and it should not be your only control, because it relies on remembering.
Does this apply outside VMware?
The mechanism applies to any tool with an implicit current target. kubectl contexts, AWS profiles, Azure subscription selection, Terraform workspaces, and even SSH config aliases all have the same shape. The blast radius differs, the failure mode does not.
What should an MSP do first?
Credential segregation per client and per environment, because it caps the damage. Then explicit targeting in scripts. Then the destructive-cmdlet guard. In that order, because the first one holds even when a human forgets.
My Take
The thread is full of people saying they checked their config after reading it, which is the best outcome a post like that can have. It is also a reminder that the most dangerous settings in our tooling are the ones we agreed to years ago and have not thought about since.
What I keep coming back to is the asymmetry. The mistake took one untargeted cmdlet and one session that stayed open. The consequence took two days, a quarter of a company's revenue relationship, and a person's job. The controls that would have stopped it are not expensive or exotic: an explicit parameter, a separate account, one session per environment, a confirmation prompt with the target printed on it. None of them are hard. All of them are habit.
There is a version of this incident that ends with a failed job and a permissions conversation, and the difference between that version and the one that happened is one line in a credential design document that most MSPs never write.
I have spent enough time around destructive automation to know that the recovery story matters as much as the prevention story. The Exchange Online PIR runbook piece was about writing down what happens after an incident so the next one is faster. This is the other half: the controls that keep the incident from reaching the point where a runbook is needed. The TV season deletion post covered the same asymmetry from the agent side, where the actor was an AI and the restore did not work.
Every admin reading this has a session open right now with more targets connected than they remember. Go and look. It takes thirty seconds, and the man who posted this week would tell you it is the best thirty seconds you will spend today.
Mathew Clark Founder, SecureInSeconds Currently: checking which vCenters my session is still holding Drafted with AI assistance - read, verified, and fixed by a human.
Further Reading
- Microsoft's Exchange Online PIR: the five runbook changes I'm making - what happens after the incident is declared
- An AI agent deleted an entire TV season and the restore failed - the same destructive asymmetry with an agent as the actor
- Java4Shell: the patch triage order - change sequencing when the window is short
- French supermarket fridges at 50C: auditing the gear nobody can patch - knowing what you actually operate
- VMware PowerCLI: Set-PowerCLIConfiguration reference - the official cmdlet documentation for DefaultVIServerMode
- VMware PowerCLI user guide: working with multiple servers - the behaviour behind $DefaultVIServer and $DefaultVIServers
- Kubernetes: configuring access to multiple clusters - the same implicit-target shape in kubectl
- AWS CLI: named profiles - how profile selection decides which account you hit



