Azure Cloud Shell PSCloudShelUtility Failure

Azure Cloud Shell works. Except when it doesn't - then you go nuclear.

Azure Cloud Shell PSCloudShelUtility Failure

Azure Cloud Shell is a convenient place to execute some command line statements. While you can pretty much do what you need with a local installation, I find the cloud shell to be more convenient in general. And, if you work somewhere as paranoid about security as I do, your local development environment is probably not truly friendly enough for your job. Living within the Azure ecosystem is generally easier in that scenario.

That said, I actually ran into a bizarre situation of a corrupted cloud shell. The error itself is pretty dang ugly and involves the inability to load Powershell within the Powershell window. If you tried to remove Powershell modules like, nothing could happen. Here's a taste of the nightmare when you opened a new instance:

Powershell state nightmare in the Cloud Shell

You can't do anything with Powershell when the shell itself doesn't load, eh? Go figure. I really wanted to unmount the storage account from my cloud shell and regenerate it since nothing really special lives there anyway. However, I could not because the dang thing would fail on dependencies even doing that. This was likely somehow related to the two versions of the AZ modules that were installed, but it shouldn't have happened the way it did.

After this made it to the Microsoft SME, we still didn't know how it got to this state. The fix, though, was funny. It was simple, which I like.

Should you find yourself with a similar situation, be brave and run a command you otherwise never really should:

rm -rf /azureuser/

That little bit of sinful Linux will recursively nuke the directory of your Powershell modules and you'll be back to a clean Azure shell. Just be smart about it, because that command unbound unironically belongs as the first entry of 8 Deadly Commands You Should Never Run.