I have tried using this on Windows 10 and 11 test VMs, both from my RMM tool (which runs the script locally on the system) but also running as a .PS1 locally from an Administrative Powershell session on both of them with ExecutionPolicy set to Bypass. (Note: My RMM tool runs the script as SYSTEM; when I use a PS1, I'm running as the system's local administrator).
On pretty much every system I've tried,cleanmgr just hangs the first time and never completes. I've tried cleanmgr both with a /sageset /sagerun setup, or just with /verylowdisk. I've used the secondary wait command, or gone without it. And when I do it as a .PS1, Cleanmgr, even with -WindowStyle Hidden still shows a pop-up, which at some point disappears, but the script stays stuck, and sits there for an hour or more (test systems have SSDs, so not slow), whereupon I give up. When I do it through the RMM tool, it either hangs just like the .PS1, or once in awhile I get an output of "Object reference not set to an instance of an object", or another error.
On some systems, if I end the script, it will then run on successive tries. But I can't get it to go consistently. So frustrating.
I'm nearly at the point of just using a bunch of scripted Remove-Item commands and skipping CLEANMGR.EXE completely, because at least those work. I'm unsure where to go otherwise.
EDIT: And the answer is it only works with -PassThru. Otherwise, it's a complete tossup. So I've added that. I'm concerned it doesn't finish before the next part of my script however (and adding "-Wait" brings the issue back), so I added "Start-Sleep -Seconds 300" to ensure I give everything time before going on to calculate how much disk space was freed during the cleanup.