VMware Cloud Community
Bob_Humber
Contributor
Contributor
Jump to solution

SRM Commands (Pre and Post Power on)

I am looking into what hooks are available in SRM to run scripts.

Ideally I would like to be able to run VI Toolkit Powershell scripts (which would be pre-power on for VM type commands, and post-power on for VM guest type commands) , and Windows Scripts (post-power on).

I initially thought that these scripts (as configured per-VM in the Portection group) would run on the VM in question. I now realise that they both run on the SRM host (the manual does not explicity say this, which might have been helpful!). To get to the point, what I need to do is identify the VM that is being started so that I can script events to happen for that VM. I was looking for variables (i.e. something like %VMName and %GuestName) that would let me run commands to reconfigure the machine in question. Does anything like this exist, or is there another way to achieve this? If there is not, I regard it as something of a shortcoming, as I would have to pass the VMname as a parameter to the scriot for each VM.

Thanks

Ax

0 Kudos
1 Solution

Accepted Solutions
srmdocs
VMware Employee
VMware Employee
Jump to solution

Here's an excerpt from a KB article that I'm working on. I think that Table 6 includes the kinds of

variables you're looking for.

Command steps run with the identity of the LocalSystem account on the SRM

server host at the recovery site. When a command step runs, a number of

environment variables are set in the execution environment. Table 5 lists the environment variables that are available to all command steps.

Table 5. Environment Variables Available to all Command Steps

Name

Value

Example

VMware_RecoveryName

The name of the recovery plan that is executing

"Plan A"

VMware_RecoveryMode

The recovery mode

"test" or "recovery"

VMware_VC_Host

The hostname of the vCenter host at the recovery site

"vc_hostname.example.com"

VMware_VC_Port

The network port used to contact the vCenter host

"443"

Additional environment variables, listed in Table 6,are set if the command step is executing on a recovered virtual machine.

Table 6. Environment Variables Available to Command Steps Running on Recovered Virtual Machines

Name

Value

VMware_VM_Uuid

UUID used by vCenter to uniquely identify this virtual machine

VMware_VM_Name

The name of this virtual machine, as set at the protected site

VMware_VM_Ref

The Managed Object ID of the virtual machine

VMware_VM_GuestName

The name of the guest OS as defined by the VIM API.

VMware_VM_GuestIp

The IP address of the virtual machine if known.

View solution in original post

0 Kudos
4 Replies
srmdocs
VMware Employee
VMware Employee
Jump to solution

Here's an excerpt from a KB article that I'm working on. I think that Table 6 includes the kinds of

variables you're looking for.

Command steps run with the identity of the LocalSystem account on the SRM

server host at the recovery site. When a command step runs, a number of

environment variables are set in the execution environment. Table 5 lists the environment variables that are available to all command steps.

Table 5. Environment Variables Available to all Command Steps

Name

Value

Example

VMware_RecoveryName

The name of the recovery plan that is executing

"Plan A"

VMware_RecoveryMode

The recovery mode

"test" or "recovery"

VMware_VC_Host

The hostname of the vCenter host at the recovery site

"vc_hostname.example.com"

VMware_VC_Port

The network port used to contact the vCenter host

"443"

Additional environment variables, listed in Table 6,are set if the command step is executing on a recovered virtual machine.

Table 6. Environment Variables Available to Command Steps Running on Recovered Virtual Machines

Name

Value

VMware_VM_Uuid

UUID used by vCenter to uniquely identify this virtual machine

VMware_VM_Name

The name of this virtual machine, as set at the protected site

VMware_VM_Ref

The Managed Object ID of the virtual machine

VMware_VM_GuestName

The name of the guest OS as defined by the VIM API.

VMware_VM_GuestIp

The IP address of the virtual machine if known.

0 Kudos
Bob_Humber
Contributor
Contributor
Jump to solution

Thanks very much, Richard

That is exactly what I was looking for - a KB article would be a good idea.

Strangely, I had just found those variables listed in the SRM log files (in C:\Documents and Settings\All Users\Application Data\VMware\VMware Site Recovery Manager\Logs on the SRM server) just before I got your email!

Regards

Ax

0 Kudos
mlockwood
Contributor
Contributor
Jump to solution

I know this thread is over a year old, but I still haven't found any documentation on the use of these variables in a command step in SRM. I'm working on a command step that I only want to run during a test (not a full recovery) of the recovery plan. I have the basic batch file below being called by the command step but I'm not having any success getting it to work as expected. When I run it manually at the CLI it seems like the environmental variable %VMware_RecoveryMode% doesn't exist so I can't test this real easy without running a test/recovery in SRM. Does anyone see a problem with what I'm trying to do here? Am i'm using the variables incorrectly?

if %VMware_RecoveryMode%==test goto test

if %VMware_RecoveryMode%==recovery goto recovery

goto :eof

:test

echo this is a DR test >> %logfile%

goto :eof

:recovery

echo this is a DR recovery >> %logfile%

goto :eof

0 Kudos
mlockwood
Contributor
Contributor
Jump to solution

I actually just figured out my problem. For anyone else's reference doing something similar, make sure the variable outputs have quotes around them...

f %VMware_RecoveryMode%=="test" goto test

if %VMware_RecoveryMode%=="recovery" goto recovery

goto :eof

:test

echo this is a DR test >> %logfile%

goto :eof

:recovery

echo this is a DR recovery >> %logfile%

goto :eof

0 Kudos