I don't want to leave this hanging, so this is where I sit: honestly I'm not comfortable assisting further with this particular request on this platform. I don't know if there will be any other side effects of doing this in an automated format. I would want to look for a way to determine an outage is about to happen like parsing for a specific error in the logs or events before simply executing.
I don't believe PowerShell can perform the SSH interactions required. Expect, Python Expect, or even the Ansible Expect package can handle this.
Feel free to use the All-Virtual Labs provided by https://labondemand.netapp.com to develop and test against. These labs cannot have the expiration extended, but you can have as many as you want back-to-back. It's where I, albeit poorly, tested the initial syntax provided.