I have completed coding this same problem in python and was trying to generate a similar logic or atleast achieve a similar result in powershell. Python Code-