Jump to content

Recommended Posts

With the below command I am able to revert a virtual machine in vmware workstation to a snapshot mentioned.

$sVMPath = <path of the vmx file of virtual machine>

$sSnapshot = <snapshot name>

$Ret = RunWait(@ComSpec & " /c VMRun.exe -T WS revertToSnapshot ""$sVMPath$"" ""$sSnapshot$"" nogui", "", @SW_HIDE)

But the problem here is the virtual machine may contain multiple snapshots with same name because multiple users use same workstation and eventually they are keeping same name sometimes like below or in attachment.

Both snapshots are with same name and in GUI we can use them with no issue.

Capture1.JPG

 

But with autoit or with vmrun command line it is showing error as 

Error: The name does not uniquely identify one snapshot

Could anyone please help me on this.

Edited by ur
Link to post
Share on other sites

Hi.

I don't use VM-Workstation, so I don't have a clue, if the VMware PowerCLI can be used with "Workstation" as well.

This script might give you a start to collect all the snapshots. Using the snapshot date, you can pick the latest one, and as powershell returns objects, you should be able to use the "youngest" snapshot later on to revert to that one.

if (get-pssnapin vmware* -erroraction silentlycontinue) {
    write "PowerCLI Extensions are available (OK)"
} else {
    write "PowerCLI Extensions don't seem to be available,"
    write "but required for this script!"
    exit
}


$VIserver="VirtualCenterServerName"

disconnect-viserver -confirm:$false -ea silentlycontinue
connect-viserver $VIserver

$SnapsExist=$true
$time=get-date -uformat "%Y-%m-%d@%Hh:%Mm:%Ss"
$TimeFile=$time -replace ":","'"
$TimeString=$time -replace ":"," "
$TimeString=$TimeString -replace "@"," um "
$TimeString = "Stand: " + $TimeString   
    
$Report = Get-VM | Get-Snapshot | Select VM,Name,Description,@{Label="Size";Expression={"{0:N2} GB" -f ($_.SizeGB)}},Created
If (-not $Report)
{  $Report = New-Object PSObject -Property @{
      VM = "No snapshots found on any VM's controlled by $VIServer"
      Name = ""
      Description = ""
      Size = ""
      Created = ""
   }
   $SnapsExist=$false
}
$Report = $Report | 
    Select VM,Name,Description,Size,Created | 
    ConvertTo-Html -Head $Header -PreContent $("<p><h2>Snapshot Report - $VIServer.<br>" + $TimeString + "</h2></p><br>")

$FTstyle = @"
<body>

<style type="text/css">
        .TFtable{
                width:100%;
                border-collapse:collapse;
        }
        .TFtable td{
                padding:7px; border:#4e95f4 1px solid;
        }
        /* provide some minimal visual accomodation for IE8 and below */
        .TFtable tr{
                background: #b8d1f3;
        }
        /*  Define the background color for all the ODD background rows  */
        .TFtable tr:nth-child(odd){
                background: #ffffff;
        }
        /*  Define the background color for all the EVEN background rows  */
        .TFtable tr:nth-child(even){
                background: #ccffcc;
        }
</style>
"@


$SaveTo=$($env:temp + "\VMs-mit-Snapshots_" + $TimeStamp + ".html")


$R2 = $Report -replace "<body>",$FTStyle
$R3 = $R2 -replace "<table>",'<table class="TFtable">'
$R3 | out-file $SaveTo
Write-host "VMs with snapshots are to be found in this HTML Report:"
write-host $SaveTo
. $SaveTo



if ($SnapsExist -and (get-pssnapin *exchange* -erroraction silentlycontinue)) {
    $smtpServer = "YourMailServerInternalIP"
    $att = new-object Net.Mail.Attachment($SaveTo)
    $msg = new-object Net.Mail.MailMessage
    $smtp = new-object Net.Mail.SmtpClient($smtpServer)
    $msg.From = "VMs-with-Snapshots@your-corp.local"
    $msg.To.Add(([adsi]"LDAP://$(whoami /fqdn)").mail)
    $msg.Subject = "VMs with snapshots, as of " + $TimeString
    $msg.Body = "open separately (The Outlook 2010 Preview Feature won't display this HTML properly)."
    $msg.Attachments.Add($att)
    $smtp.Send($msg)
    $att.Dispose()
}

Regards, Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By ThePappas
      I am feeling really stupid. I cannot figure out what I am doing wrong.
      I followed the "Winzip" example, and I cannot get autoit to simply send an enter when the first window appears.  There are 2 windows like that, and neither one gets the enter.
      ShellExecute("VMware-EnhancedAuthenticationPlugin-6.7.0.exe") WinWaitActive("VMware Plug-in Service Installer.","instances will be closed") Send("{ENTER}") WinWaitActive("VMware Plug-in Service Installer.","run in succession") Send("{ENTER}") WinWaitActive("VMware Enhanced Authentication Plug-in 6.7.0","Welcome to the installation wizard") Send("!n") WinWaitActive("VMware Enhanced Authentication Plug-in 6.7.0","End-User License Agreement") Send("!a!n!n!i") WinWaitActive("VMware Enhanced Authentication Plug-in 6.7.0","Change") Send("!n") WinWaitActive("VMware Enhanced Authentication Plug-in 6.7.0","Install") Send("!i") WinWaitActive("VMware Enhanced Authentication Plug-in 6.7.0","Finish") Send("!f") WinWaitActive("VMware Plug-in Service","Welcome to the installation wizard") Send("!n") WinWaitActive("VMware Plug-in Service", "End-User License Agreement") Send("!a!n") WinWaitActive("VMware Plug-in Service", "Install the VMware Plug-in Service in") Send("!n") WinWaitActive("VMware Plug-in Service", "Install") Send("!i") WinWaitActive("VMware Plug-in Service","Finish") Send("f") I used the Window ID tool to verify that I am using the correct title, and those substrings appear in the dialog.
      I really did not want to have to post here, as this seems like a trivial effort.  But I am stuck.  I hate stuck.
      Thanks!
    • By Jemboy
      I use Vmware Workstation to run servers, client and other devices. The reason I use Workstation instead of Esxi is because I find it easier to copy the VM files when the host machine crashes (just unplug *raid 1* disk and add it to the new host). 
      Because I do not want to reinstall everytime, I often copy an existing VM to test something  or just use the copy a base to install other apps.

      In the past I used to use VmConverter, but the latest version won't copy/rename my latest VMs anymore and the older VmConverters do not support the last VM-format.
      So  I decided to make my own "VmConverter" and called it "VMRenamer".
      I post this as is (it's working for me) and I encourage others to enhance the program as needed.
      Pre-requisites:
      You have to have VMWorkstation installed (I asume on a X64 Windows) You may NOT have snapshotted the VMware in ANY way, even after deleting the snapshot the VM is changed to much for my program to reliabily rename/change the VM files. I have used some snippets from other in my source and I wish to thank them for posting those on the forum/internet.
      Some remarks or obsolute functions have not been removed, because I wanted to post this for you out there instead of delaying the post longer.
      Enjoy!
       
      VmRenamer_1Q_2.zip
    • By ur
      Which Powershell command in the PowerCLI module for VMware ESX used to interact with UI apps?
       
      When I launch any exe/any exeutable using powercli on guest VM using powercli command.
      Invoke-VMScript, I am able to run them in the background but not in the foreground.
       
      i.e., UI apps are not launching but showing the background as running in the task manager.
       
      We need our UI Automation scripts to execute in the VM, but it is not working.
       
      We are able to do in virtualbox and hyper-v but not in vmware esx using powercli.
       
      Please suggest.
    • By griefman
      Hi everyone,
      i am writing to you after a very long struggle i had while trying to figure out how to send a simple click inside a virtual machine running in vmware workstation 14.
      i have an autoit script running on my host machine watching for the UAC prompt to be displayed in a running vm. Both the host and the guest OS are Windows 10. This script worked perfectly with virtual box. It recognized the UAC prompt and clicked inside and the UAC was accepted. Since i switched to VMware Workstation 14, the script no longer clicks inside the VM successfully. It acts as if it clicks, but it doesn't. 
      I tried sending key combinations instead of a click, so that the VM can grab the input, but it also did not work. Every attempt that i made to send clicks or keys from the host inside the VM did not work. I tried using:
      MouseClick
      ControlClick
      MouseMove
      _WinAPI_Mouse_Event
      _WinAPI_Keybd_Event
       
      I also noticed that while the cursor moves to the target which has to be cilcked when my vmware worstation window is not focused, it even doesn't do that when i WinActivate the vmware workstation window first.
       
      Did anyone experience such an issue, or maybe could give me a hint, what else i could use to send a key combination or a mouse click in a vmware workstation 14 pro guest window?
       
      here is my code, which works with virtualbox:
       
      #AutoIt3Wrapper_Icon=".\uac.ico" #include <ImageSearchSubrogated.au3> FileInstall(".\ImageSearchDLL.dll", ".\ImageSearchDLL.dll", 0) FileInstall(".\UAC_ginloSetup.bmp", ".\UAC_ginloSetup.bmp", 0) FileInstall(".\UAC_Yes.bmp", ".\UAC_Yes.bmp", 0) ; set global variables for the coordinates, which should be delivered global $x1 = 0, $y1 = 0 global $x2 = 0, $y2 = 0 global $counter1 = 0 global $counter2 = 0 global $sleep = 10000 global $smallSleep = 5000 ; execute the script in a loop, so that it will hopefully recover from some unexpected errors While $counter1 < 1 checkForImage() WEnd #cs ------------ Functions #ce ------------ Func checkForImage() While $counter2 < 1 ; search for the UAC in the entire screen - 2 screens supported local $searchUac = _ImageSearchArea('UAC_ginloSetup.bmp', 1, -2568, -8, 5136, 1440, $x1, $y1, 0) If $searchUac = 1 Then ; if the UAC was found search for the Yes button in a an area 200 x 200 from the middle of the found UAC image local $searchYes = _ImageSearchArea('UAC_Yes.bmp', 1, $x1, $y1, $x1 + 200, $y1 + 200, $x2, $y2, 0) If $searchYes = 1 Then ; if the Yes button was found click it and pause the script for $sleep seconds MouseClick("left", $x2, $y2, 1,0) Sleep($sleep) Else ; if the Yes button was not found retry from the beginning in $smallSleep seconds MsgBox(0, "UAC found error", "UAC was found but the 'Yes' button was not found. Script will retry in " & $smallSleep & " seconds.", $smallSleep) EndIf ; another way to accept the UAC - via shortcut ;Send("{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}") ;Send("!y") Else ; if UAC was not found try again in $sleep seconds Sleep($sleep) EndIf WEnd ; if some error occured which expired the loop, pause the script for $sleep seconds MsgBox(0, "Error", "Some Error expired the timer and the script could not recover. The script will restart in " & $sleep & " seconds.", $sleep) EndFunc  
    • By davidacrozier
      Hello all ~
      I am running an autoit script on Windows 10 inside VMware Workstation 12 Pro version 12.5.2.  Technically I am remoting into ESXi which has a Domain Controller (DC), WebServer, FilServer, Windows 10, etc.  Using the GUI (i.e. running explorer.exe) I am able to open several different folders successfully.  The desktop, documents, USB external all open without issue.  The network share opening gives me issues.  Whenever I attempt to open \\filserver\users\user\sharedfolder I get the documents folder instead.  I understand that the documents folder is the default for explorer.  I have also attempted to use the letter drive mapped to the network share (Z:) and receive the same result.  When I run this script on Windows 10 alone without  the VM or the ESXi I am able to open the network share without problems.  I have tried to use the net use command to designate a letter M: to the network share folder prior to running the script.  This did not work for me.  
      One additional avenue I think might work is to use the systreeview321 and _GUICtrlTreeView_FindItem to step through the tree looking for the network share.  Once found,  double click on it and see if that opens the shared network folder.  I can click inside the VM with my mouse on the network share and it opens just fine.  Not sure if running up against GUI issues, or permission issues, or what?
      Thanks in advance,
      Davida Crozier
      TestNetworkShare.au3
      This script is a subset of a much larger program, but it illustrates what I am dealing with.

×
×
  • Create New...