Hi there! My name is, Zadee. I'm an Independent Advisor and a Microsoft user like you. Sorry to hear about your experience.
If you're trying to create a script, it's probably best to post your query to the sister forum MS Q & A where you're likely to get an answer. IT professionals/programmers that use these products like you do discuss these types of topics in there.
https://learn.microsoft.com/en-us/answers/index...
Thank you for your understanding.