Need a help in creating a powershell script

I need your help to create a script for a Virtual Windows Server. I have a VM at Site1. However, when I want to Power ON that VM at Site2 (In case of any issue with Site1), I do the manual IP change in that VM, which I want to automate through a script. So, it will be like this

Variables
IP1 10.10.10.10  
Subnet1 255.0.0.0  
Gateway1 10.10.10.1  
IP2 20.20.20.20  
Subnet2 255.0.0.0  
Gateway2 20.20.20.1

At windows reboot, the script will execute (as scheduled in the Scheduled Tasks)

Ping gateway1
if gets a response  - exit

if not  
execute the following command       
netsh interface ipv4 set address name="Local Area Connection" static 20.20.20.20 255.0.0.0 20.20.20.1  
ipconfig /registerdns  
ping gateway2  
if gets response   - exit

if not  
execute the following command  
netsh interface ipv4 set address name="Local Area Connection" static 10.10.10.10 255.0.0.0 10.10.10.1  
ipconfig /registerdns    
ping gateway1    
if gets response - exit

if not
repeat both of the above checks