Hi there,
Make sure you have updated with all patches on server 2022, their is a known issue of powershell script not working and has been resolved in KB5014678
2022-06-14.
Resolved issues in Windows Server 2022 https://learn.microsoft.com/en-us/windows/release-health/resolved-issues-windows-server-2022
-----------------------------------------------------------------------------------------------------------------------------------------
--If the reply is helpful, please Upvote and Accept it as an answer--