I noticed this issue at a customer where they were deploying machines using SCCM and automatically configuring the machine name according to the serial number.
What is the 0x8022005 error in SCCM?
There were no issues with deploying physical machines, but virtual machines were failing during the Apply Windows Settings step with the following error code:
Failed to open the Task Sequencing Environment. Code 0x80220005. Please ensure you are running this executable inside a properly configured OS
The reason why we see this issue is that virtual machines have longer serial numbers than 16 characters, which is the maximum amount of characters allowed for a machine name during OSD.
How to fix the error
If you have a script that sets the serial number automatically, you will need to configure it to only take the first 16 characters of the serial number.