VMware Cloud Community
Bruticusmaximus
Enthusiast
Enthusiast

Calling a powershell script from SRM appliance

Before we run a disaster recovery test, there's a few house keeping things we need to do. There's a couple of production domain servers at the DR site that we need to clone. During the test we use the cloned versions of these DCs.  After the test, we delete the clones and power up the original DCs.  Why we do this is a long story.

Years ago when SRM was still Windows based, we had a Powershell script on the SRM server that would do the clone.  We'd call it from SRM at the beginning of the recovery plan.  

Now that SRM is an appliance, I manually run the script before I run the SRM recovery plan.  I would love to somehow incorporate this script at the beginning of the recovery plan.

Also, is there a way to incorporate the calling of a powershell script during the cleanup process in SRM?


0 Kudos
7 Replies
vbrowncoat
Expert
Expert

The ways to run powershell as part of a recovery plan are:
1. Call a script on the appliance (using bash, perl or python) that will call the powershell script on another VM. Ideally this other VM will always be running at the recovery site.

2. Run a script on a recovered VM

 

Regarding running a script during cleanup, we haven't added this capability yet. It is something we're working on though.

Gr23
Contributor
Contributor

Hi,

I have been looking to implement this, do you have example code how you managed to do this. 

 

Thanks

 

 

 

0 Kudos
Hertzon
Contributor
Contributor

i'm looking for it too, do you have some example of the script?

0 Kudos
Bruticusmaximus
Enthusiast
Enthusiast

I tried running a bash script on the SRM appliance that would call a Powershell script on a utility VM but, couldn't get it to go.  I was investing too much time into it and just gave up.  The simple solution is to just go back to the Windows version of SRM.  So our DR test is automated now except for one manual step. It would have been cool to have it completely automated like it used to be before upgrading SRM.☹️ 

 



I submitted a feature request so, we'll see how that goes.

0 Kudos
padulka
Hot Shot
Hot Shot

Follow because I'm interested to this issue; I think it's impossible that the solution is to migrate to windows installation

0 Kudos
Leon_Eric
VMware Employee
VMware Employee

I have an end user which just migrated to SRM appliance.  

Do you happen to have an example script(bash/per/python) that running on the SRM appliance, which calling the VM that on the same network which the script resides on ? 

They don't have the expert in house to rewrite such lengthy scripts in Perl/Python.

 

Thanks in advance.

0 Kudos
Codiyapa
Contributor
Contributor

This should work

PowerShell script that runs locally on windows SRM server version fails to run after photon OS version of SRM as it does not have access to the SRM Runtime environment variable.  SRM is now external .

SRM Runtime variablehttps://docs.vmware.com/en/Site-Recovery-Manager/8.5/com.vmware.srm.admin.doc/GUID-2D288B46-27D1-41E... 

No need to change the entire PowerShell script, just a small piece of code injected on SRM appliance should work.

Step1 : Search your PowerShell script for anything starting with $ENV.  . It is  a environment variable for example $ENV.VMware_RecoveryName, $ENV.VMware_RecoveryMode, $ENV.VMware_VC_Host, $ENV.VMware_VC_Port. 

Step2 : SSH into the SRM appliance as 'admin' . upload the getEnv.py on /admin/home directory . If you want to use any other user please select the appropriate permission and location. 

Step3: go back to PowerShell script, you will need plink.exe to SSH  (download from https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html

Step4: To get the environment variable into your PowerShell script 

$command = "python getEnv.py " + {prev SRM variable name} 

 $windows_var= Write-Output 'y' | & $PLINKPATH -pw $SRMpassword $sRM_USERNAME@$SRM_hostname $command

example :  $command = "python getEnv.py " + "VMware_RecoveryName"

getEnv,py returns the SRM runtime variable value in Uppercase or return 'NONE' . Have a if condition to check the value is not 'NONE' 

 

 

 

0 Kudos