Are you open to a GPO Computer Startup Script?
https://home.memftw.com/configmgr-client-startup-script/
We ourselves use a variant of a GPO computer startup script. The one at this link is the one I've heard the most about; but others may comment with different ones or newer ones; I haven't been keeping track. But it's certainly a place to start.
I wonder if someone has a powershell version that I've forgotten about.
These gpo computer startup scripts have been part of the cm world for years; and a lot of fixes have been added to them over the years, to keep client installs clean and happy.