VMware Cloud Community
WAMTech
Contributor
Contributor

Running a customized script in the VM after initial boot up

Hi all I am working with SRM 1.0.1 Update 3 with ESX 3.5 U4 and VC 2.5 U4. I have successfully configured SRM and ran a few test, now I want to try to see if I can run a few VBS scripts during the Post power on steps of the recovry process. There area a few application specific changes that must be done in order for our application to work on our DR environment. Basically I have a few websites that need a URL to point to a differnt server. I tried adding the script in the post power on steps but it failed. Iread somewhere and I can't find it again for the life of me, that the scripts on the Post Power On Stesps execute on the Virtual Center, but I want the scripts to run from each of the virtual manchines to make the appropriate change. Does anybody have any idea or recommendations?

Thanks in advance.

Reply
0 Kudos
1 Reply
Smoggy
VMware Employee
VMware Employee

There certainly is a way to invoke a script in a guest OS remotely and it is called ‘Invoke-VMScript'. The Invoke-VMScript cmdlet can be used to run scripts/commands inside a guest Windows VM. You could use this to simply call and execute a locally stored script/command, for example see this video: http://www.vimeo.com/1770070?pg=embed&sec=1770070

Alternatively you can go one step further and dynamically build the script and push it to the guest, which is pretty cool!

For example, below is a function from a script that a colleague of mine used to configure static IP addresses on the multiple VirtualCenter VMs that were used in the VMworld 2009 PowerShell Lab.

Function Set_VirtualCenterIP ($VC_VM, $VC_IP, $VC_NM, $VC_DG, $VC_DNS1, $VC_DNS2) {

$IP_Script = @"

`$NetworkConfig = Get-WmiObject -Class Win32_NetworkAdapterConfiguration

`$NicAdapter = `$NetworkConfig | where {`$_.DHCPEnabled -eq 'True'}

`$NicAdapter.EnableStatic('$VC_IP','$VC_NM')

`$NicAdapter.SetGateways('$VC_DG')

`$VC_DNSarray = '$VC_DNS1','$VC_DNS2'

`$NicAdapter.SetDNSServerSearchOrder(`$VC_DNSarray)

"@

$VC_VM | Invoke-VMScript -HostUser $ESX_User -HostPassword $ESX_Passwd -GuestUser "Administrator" -GuestPassword "vmware" -ScriptText $IP_Script #-ErrorAction SilentlyContinue

}

To use this technique you would need to install PowerShell and the VIToolkit on to your SRM Server and PowerShell and VMware Tools in each of the VMs.

Reply
0 Kudos