• This topic has 2 replies, 3 voices, and was last updated November 13, 2016 by Damian D.

Utility for running failover scripts in a guest

  • Here is a simple executable that can run commands in a guest VM. It can be used to run the failover script in a guest as opposed to within the ZVM.

    All you need to do is open this zip somewhere on the ZVM and run the executable from the FO script providing as command line parameters all of the credentials and the program to run within the guest VM.

    Senior Technical Architect at Zerto
    Tagged: 

    Hi Shannon. Looks like attachments didn’t make their way through the transition to myZerto.

    Any chance you could re-attach to this post?

    Thanks!

     

    Tagged: 

    Looks like the utility mentioned here is not attached.  I was able to use the below script to run a command inside of the GuestOS, run it in VMware PowerCLI.  Now that I have it working it shouldn’t be too hard to make it work with Zerto’s pre post failover script on the VPG.

    The script uses “Invoke-VMscript”, the way it works is that ESXi host tells VMware tools to run a command inside of the GuestOS.

    The below script changes the IP and DNS settings inside of the guestOS that you specify.  The plan is to re-ip a Windows 2000 box after a failover.  Change “Connect-VIServer vcenter1.mylab.local” so that it points to your vCenter.  When executed it will prompt you for the VM name, ESXi host password, GuestOS username/password and then it will run the 3 netsh commands listed below.

    http://www.virtu-al.net/2010/02/05/powercli-changing-a-vm-ip-address-with-invoke-vmscript/

    To get it to work in Windows 2003, etc, you will need to change the path to netsh.exe.

    Win2000IPDNSChange.ps1

    Function Set-WinVMIP ($VM, $HC, $GC, $IP, $SNM, $GW, $DNS1, $DNS2){
    $netsh = “c:\WINNT\system32\netsh.exe interface ip set address “”Local Area Connection”” static $IP $SNM $GW 1″
    $netshdns1 = “c:\WINNT\system32\netsh.exe interface ip set dns “”Local Area Connection”” static $DNS1″
    $netshdns2 = “c:\WINNT\system32\netsh.exe interface ip add dns “”Local Area Connection”” $DNS2 index=2″
    Write-Host “Setting IP address for $VM…”
    Invoke-VMScript -VM $VM -HostCredential $HC -GuestCredential $GC -ScriptType bat -ScriptText $netsh
    Write-Host “Setting IP address completed for $VM.”
    Write-Host “Setting DNS1 for $VM…”
    Invoke-VMScript -VM $VM -HostCredential $HC -GuestCredential $GC -ScriptType bat -ScriptText $netshdns1
    Write-Host “Setting DNS1 completed for $VM.”
    Write-Host “Setting DNS2 for $VM…”
    Invoke-VMScript -VM $VM -HostCredential $HC -GuestCredential $GC -ScriptType bat -ScriptText $netshdns2
    Write-Host “Setting DNS2 for $VM completed.”
    }

    Connect-VIServer vcenter1.mylab.local

    $VM = Get-VM ( Read-Host “Enter VM name” )
    $ESXHost = $VM | Get-VMHost
    $HostCred = $Host.UI.PromptForCredential(“Please enter credentials”, “Enter ESX host credentials for $ESXHost”, “root”, “”)
    $GuestCred = $Host.UI.PromptForCredential(“Please enter credentials”, “Enter Guest credentials for $VM”, “”, “”)

    $IP = “192.168.0.81”
    $SNM = “255.255.255.0”
    $GW = “192.168.0.1”
    $DNS1 = “192.168.0.100”
    $DNS2 = “192.168.0.101”

    Set-WinVMIP $VM $HostCred $GuestCred $IP $SNM $GW $DNS1 $DNS2

    Tagged: 
You must be logged in to create new topics. Click here to login