'Azure DevOps: Did PowerShell version spontaneously downgrade?

I created a PS script to run from my Azure pipeline. The script used the Remove-Service cmdlet. The online docs have a note saying that Remove-Service is only in PS 6.0 and later.

So I checked to see whether AZRPOCDEV2, my Azure VM, had PS >= 6.0, and it did. I successfully ran a script containing Remove-Service many times between March 30 and April 6.

Then today I got this error message:

The term 'Remove-Service' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

So I logged into my VM and ran the command Get-Command Remove-Service, and it wasn’t there. I checked the PS version on AZRPOCDEV2, and it’s PS 5.1.

So I have a couple of questions that I cannot answer.

  1. How or why did Azure downgrade my PowerShell from 6.x to 5.1?
  2. How can I get it back to 6.x?
  3. Did I imagine all of this, and Remove-Service never really did work??

I tried installing PowerShell 7, and that’s fine, but it doesn’t use the same config files and macro file as PS 5.1. Plus my Azure DevOps pipeline (or agent) keeps running the default PS 5.1.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source