wait for CloneVM_Task

Hello

I am new to Powershell and PowerCLI and already searched the net and this forum for the answer to my question but he had so far without success.

I want to write a script that clone a virtual machine, then informs about the success or failure of the clone operation by sending a mail.

The Clone operation is already working:

....

$clonetask = $_this. CloneVM_Task ($folder, "myvm-clone", $spec)

...

However, I have no success in anticipation of the CloneVM_Task at the end and get the exit status.

I tried for example:

While {($clonetask.Info.State-eq "running")}
sleep 1
Write-Host "cloning...". »
}

but it does not work.

All Tips how to do this correctly?

concerning

Markus

I did not notice that you did not convert the MoRef task on a Task object.

Try like this

$clonetaskMoRef = $_this.CloneVM_Task($folder, "myvm-clone", $spec)$clonetask = Get-View $clonetaskMoRefwhile("running","queued" -contains $clonetask.Info.State){  Write-Host "Task state $($clonetask.Info.State) ...."  sleep 1  $clonetask.UpdateViewData("Info.State")}

Write-Host "Final task state $($clonetask.Info.State)"

Tags: VMware

Similar Questions

  • Script to wait for Clone task is completed

    Good day, as part of the post, I run a command that enables the NIC and sets the right Port-Group of cloning process. I put a sleep command in each environment is diferrent, so I find myself always change this duration of sleep because the cloning process does not end in the time of sleep and the rest of the script fails. So in order to get rid of the sleep control that I want to capture the CloneVM_Task and pass this parameter to wait-task that will force the completion of the ClonVM_Task. I could just make sure no other tasks are running but this task, but as we all know that alays can't be the case. So that's what I did.

    I begin a deployment of FVO to have an another long running task. Then I run the script.

    If ((Get - PSSnapin - name Vmware.VimAutomation.Core - ErrorAction SilentlyContinue) - eq $null) {Add-PSSnapin "Vmware.VimAutomation.Core"}

    # Virtual Center details
    $server_address = "MYvCenter name" or IP

    SE connect-VIServer-Server $server_Address - user username-pass password - WarningAction SilentlyContinue


    #Create Master VM Templates
    #
    # Here we import the CSV file with the account information and he piped in a Foreach-object
    # Creating a Variable that imports the csv file that contains all data of the virtual machine

    CD "e:\Scripts.
    $InputFile = import-Csv "E:\scripts\mycloneinput.csv".
    $InputFile | {ForEach-Object

    $ip = $_. VM_IPAddress
    $GName = $_. VM_Guestname
    $TName = $_. Template_name
    $HName = get-VMHost "myhostname" # 1 first Select
    $Desc = $_. Description
    $Dstore = $_. Datastore_Name
    $Spec = $_. Customization
    $Folder = $_. Folder
    $Sfolder = $_. Subfolder
    $NIC = $_. NIC
    $NIC_Lable = $_. NIC_Label
    $Gateway = $_. NIC_Gateway
    $SubnetMask = "255.255.255.0".
    $DNS1 = $_. DNS1
    $DNS2 = $_. DNS2

    Write-host "creation: ' $GName
    Write-host "template name is: ' $TName

    # This takes variables and creates the virtual machine
    Get-OSCustomizationSpec $Spec | Get-OSCustomizationNicMapping | »
    Game-OSCustomizationNicMapping - IpMode UseStaticIP - $ip - $SubnetMask subnet mask - DNS IpAddress $DNS1, $DNS2 - DefaultGateway $Gateway
    New-VM-name $GName - location $Folder - model $TName - host $HName - $Dstore - $Desc Description data store - OSCustomizationSpec $Spec - RunAsync-confirm: $false

    #######################################
    #Waiting for cloning process to finish.
    #######################################

    $$$ Under notes show a little history of how I got to this point.

    $$ Note1: the first attempt, I just captured running tasks and their past to the task pending. "Well, since the deploy OVF and ClonVM_Task where it runs would wait up to two when completed by the end."

    $$ Note2: so I added the If Else loop below that failed, because $RTask never equaled only CloneVM_Task, but was a table of two.

    $$ Note3: I tried to us below to separate the two tasks to help

    # $RTask = get-task-status running (who captured the two tasks running)

    # $Array = $Rtask.Split("") (Errored with the method call failed because [System.Object []] contains a method named 'Split'.)
    # So I tried to divide the table like this. ForEach ($Task in $Rtask.Name - Split("")) {Write-Host "my tasks are:" $Task}


    Get-task-status Running | Export-CSV "E:\scripts\Current_Tasks.csv".
    $InputFile2 = import-CSV "E:\scripts\mmca\mmca_Current_Tasks.csv".
    $InputFile2 | {ForEach-Object
    $RTask = $_. Name
    Write-Host "current task is: ' $RTask
    IF ($RTask - eq "CloneVM_Task") {}
    Write-Host "current task of Clonning is: ' $RTask
    Write-Host "in the meantime the cloning process finish.
    Waiting-task-task $MyTask
    }
    Else {}
    Write-Host "no cloning process is executed.
    }
    }

    # This allows the NIC and set the correct Port Group
    Get-VM-name $GName | Get-NetworkAdapter-name $NIC | Together-NetworkAdapter - NetworkName $NIC_Lable-confirm: $false - StartConnected $true

    }

    When I run the present, I get the following:

    # #This shows the task start Clonning #.

    erverId: /[email protected]:443 /
    Status: running
    IsCancelable: true
    PercentComplete: 5
    StartTime: 03/05/2013 00:52:13
    FinishTime:
    ObjectId: VirtualMachine-vm-382
    Result:
    Description: Clone virtual machine
    ExtensionData: VMware.Vim.Task
    ID: Work-task-2070
    Name: CloneVM_Task
    UID: /[email protected]:443 / task = work-work-2070 /

    #########################################################

    # #Runs through the tasks running.

    Current task: deploy the model to the FVO
    No cloning process is executed

    # Ignore deploy it task #.

    # #Matches the If statement and continues to process #.
    Current task is: CloneVM_Task
    Task current Clonning is: CloneVM_Task
    Wait for the cloning process to complete

    # #Error #.

    Waiting-Task: cannot bind parameter 'task '. Impossible to convert the value of 'CloneVM_Task' to type 'System.String' type 'VMware.VimAutomation.Sdk.Types.V1.Task '.
    E:\scripts\Working_Create_Master_Templates.ps1:71 tank: 24
    + Wait-task-task < < < < $RTask
    + CategoryInfo: InvalidArgument: (:)) [waiting-Task], ParameterBindingException)
    + FullyQualifiedErrorId: CannotConvertArgumentNoMessage, VMware.VimAutomation.ViCore.Cmdlets.Commands.WaitTask

    $$$ Under notes show a little history of how I got to this point.

    Note1: The first attempt, I have just captured tasks currently running and pending their past to the task. "Well, since the deploy OVF and ClonVM_Task where it runs would wait up to two when completed by the end."

    NOTE2: So I added the If Else loop below which failed because $RTask never equaled only CloneVM_Task, but was a picture of two tasks.

    Note3: I tried to use the following to divide the two tasks:

    $RTask = get-task-status running (who captured the two tasks running)

    foreach ($Task in $Rtask - Split(""))
    {
    {Write-Host "my tasks are:" $Task}
    IF ($Task - eq "CloneVM_Task") {}
    Write-Host "current task of Clonning is: ' $Task
    Write-Host "in the meantime the cloning process finish.
    Waiting-task-task $Task
    }
    Else {}
    Write-Host "no cloning process is executed.
    }


    }

    # #Output the little script above #.

    Current task: deploy OVF model CloneVM_Task
    My tasks are: deploy
    My tasks are: OVF
    My tasks are: model
    My tasks are: CloneVM_Task
    Task current Clonning is: CloneVM_Task
    Wait for the cloning process to complete
    Waiting-Task: cannot bind parameter 'task '. Impossible to convert the value of 'CloneVM_Task' to type 'System.String' type 'VMware.VimAutomation.Sdk.Types.V1.Task '.
    Online: 11 char: 24
    + Wait-task-task < < < < $Task
    + CategoryInfo: InvalidArgument: (:)) [waiting-Task], ParameterBindingException)
    + FullyQualifiedErrorId: CannotConvertArgumentNoMessage, VMware.VimAutomation.ViCore.Cmdlets.Commands.WaitTask

    I'm new to Powercli and I've scoured Google for a possible answer. I thought I might have a solution that has been published on the VMware PowerCLI Forum, but I couldn't get this to work. Any help would be greatly appreciated.

    #########################################

    I wasn't worried about how to tasks where splits, unless I was trying to follow the import fo the OVF, so that the script went into the loop If and as one of the names for CloneVM_Task then he Treaty. But I got the same error I did in the last version of the above script. That's why I have the version curent thinking that if I exported and then imported the tasks it might make a difference.

    I'm new to Powercli and would like a little help. I am either very close or by a mile off. :-)

    Thank you

    Mitch

    Why don't you store the the task object that is returned when you use the RunAsync switch?

    You can create a loop around the State and wait until the clone job is done.

    $task = New-VM -Name MyVM ... -RunAsync 
    
    while($task.ExtensionData.Info.State -eq "running"){
      sleep 1  $task.ExtensionData.UpdateViewData('Info.State')
    }
    

    The big difference with the Wait-job cmdlet, it is that this will allow you to perform additional work in the While loop.

    Waiting-task the cmdlet waits just until the task is finisned and you can not do anything else.

  • Stuck "waiting for the printer to be available."

    After initially looking at it's going to print, the printer dialog box displays "waiting for printer to be available" and it's there (even if the printer - inkjet HP series C3800 - is ready).

    Here is what I tried:

    Using the HP utility software on the same computer, I am able to successfully print a test page, which rules out a problem with the printer and its connection to the computer.

    Printing worked normally before moving on to the Sierra. I tried resetting the printing system and add new printer (Sierra recognizes very well). I also tried to run in case disk utility have a permissions problem.

    I'm stumped at this point. Help much appreciated.

    Same story, but with a HP Laserjet P3005dn, specific scenario, the exact symptoms, exact attempts to improve...

  • Hi8 thru cam HDV into FCP 7: waiting for timecode

    Hello

    I have a bunch of Hi8 tapes I want to capture on the drive by running through Sony CCD-TR400 on the Canon HV - 20 MBPro & FCP 7.

    I can see the execution in the window capture, but when I hit capture now it gets no further than "Waiting for time code."

    I guess the Hi8 analog, but hoped the Canon with its AV > DV option would treat his way through.

    Any ideas?

    Is the only way to do this would save on tape dv on Canon HV-20 and then capture the disk?

    The best

    Elmer

    Hi8 uses only consumer re-writable (CCFC) timecode that is not readable by the PCF.  In the FCP capture settings, set "Device Control" device not controllable and then use Capture now capture rather than in batches.

    -DH

  • "waiting for encrypted google" does not allow me to open a Web site

    When I try to open lifenews.com, which I visited many times, there is a message saying left down "waiting for encrypted google." I don't even use google chrome? I don't know where to go to get rid of it, I don't want nothing blocked unless I specifically ask to be blocked. I did the research, said it's a blur, said another security settings to uncheck the ssl2 and ssl3. Nothing works. Can someone tell me please how to remove this thing waiting for encrypted google.

    You said blur, which is an add-on. Use the blur, or any extension of similar content filtering? If you think one of them might be the problem, you can test Firefox Safe mode. It is a standard diagnostic tool to disable extensions, hardware acceleration, and a few other advanced features of Firefox.

    Does not work if Firefox: Hold down the SHIFT key when you start Firefox.

    If Firefox is running: You can restart Firefox in Mode safe mode using either:

    • button "3-bar" menu > "?" button > restart with disabled modules
    • Help menu > restart with disabled modules

    and OK reboot.

    Two scenarios: A small dialog box should appear. Click on 'Start mode safe' (not update).

    Any improvement?

  • iMessage is stuck at waiting for Activation.

    Hello

    I have iPhone 6 Plus with iMessage stuck waiting for activation. May that what's wrong with it? These are the work with other vendors if I insert the sim card. Is it something to do with the question SMS relay or something else?

    Need help to solve my problem.

    Thanks in advance.

    If you get an error when you try to activate FaceTime - Apple Support or iMessage

  • How long should you wait for your apple account unlock

    How long should you wait for your apple account unlock?

    of > If your identifier Apple is locked - Apple supports

    ...

    When you see one of these alerts, you can go to iforgot.apple.com to unlock your account with your existing password or reset your password. After multiple unsuccessful attempts to unlock your account, your identifier Apple will remain locked and you can try again the next day.

    ...

  • Extend my extreme network with another extreme - waiting for internet access

    Hello - I have a new generation Airport Extreme (let's call it Extreme1) connected to a Comcast modem and it works very well. The extreme will be the router that the modem has no router function. I'm trying to expand my network to another room with another extreme (let's call it Extreme2). I have a connection cable between two rooms. Extreme1 has an ethernet cable from one of its LAN ports connected on port WAN Extreme2. When I try to create a new network with Extreme2 (in aid of the same name, passwords, etc.) it does not work. He was suspended at the end when he is looking for a connection ("Waiting for internet access")-I did the following things based on what I read here:

    1. Changed IPv6 link local parameters
    2. Tried the whole upward on my Macbook and tried on my iphone
    3. The Wan first and then tried to change the configuration after you done for Extreme2 by creating a network
    4. Tried to create a network with Extreme2 connected directly to the modem
    5. Extreme2 factory reset after every attepmt

    And nothing works. Kicker is, I also have a reasonably new airport express and the same thing happens to her as well.

    Do I need to adjust some parameters of network that I'm not aware of? Is it possible that my LAN ports are disabled on Extreme2? It is brand new.

    Thanks for any help.

    Have you used the Apple Setup Assistant?  If you did, it had notified you that the extreme second was being configured "add using Ethernet. The wizard will automatically configure the second airport with the appropriate settings for you.  All you have to do is enter a name of device for the second AirPort Extreme.

    Here I'm assuming that you reset the second extreme to parameters by default until you set it up again and that your second Extreme is the current version of the "tower" or that of previous versions "flat or square.

    The example below shows an AirPort Express as the device which is the extension of the network, but you will see the name of your network and AirPort Extreme on your configuration screen.

    Post back if you need some tips on using the "Wizard" for your configuration.

  • photos has not been loaded for weeks (usually the browser chrome on PC windows at work).  I tried now on some other computers and get the same error message and I report every time.  can I do or just wait for someone to fix it

    photos has not been loaded for weeks (usually the browser chrome on PC windows at work).  I tried now on some other computers and get the same error message and I report every time.  is there anything I can do or just wait for someone to fix it?

    If you want any help here, you'll have to tell us what the error message.

    Which report you errors to?

  • iPad 4 blocked mode recovery, itunes waiting for ipad

    I've had my IPad for over two years now and it worked great. But yesterday it just no longer lights. I don't know weather it auto-updated or not, but it became all black. I tried to reload, but the screen remains black after hours of load. The combo of home button and lock 10 seconds also does nothing. I plugged into my Macbook so and tried Itunes. ITunes says "ITunes has detected an iPad in recovery mode. You must restore this iPad before it can be used with iTunes. «So I press ok and restore the iPad, software is extracted and it said "Waiting for iPad...» "for a minute. The next thing is the error message ' the iPad could not be restored. An unknown error occurred (4005). "I tried several times with different cables and USB ports... I don't know what to do anymore.

    I'd be happy for something useful!

    You can try the DFU mode

    If you are unable to update or restore your iPhone, iPad or iPod touch - Apple supports

    If this does not help

    An appointment of 'Genius' to an Apple Store, or select another authorized service provider.

  • Buy 2015 MacBook Pro now or wait for 2016 model?

    My 'vintage' 2009 MacBook Pro 13 '' is very, very slowly.  Should I buy a 2015 now or wait for the 2016 model?  Thank you

    Do you need one now? If so, buy it now.

    Can you expect? Then wait.

    We are just a user like you, we have no crystal ball on the functions or future improvements of any Mac.

  • Still waiting for the new Satellite U840T-102

    We sent the laptop in the subject to support Toshiba in Italy on 5 May. File n. 73040100. After a few emails June 20, we received the proposal to change the product and sending us a new.

    We have NOTHING yet. Our clientele is more waiting for two months for a WARRANTY SERVICE.

    Is this right? It is the policy of TOSHIBA?
    CAN WE HAVE A CERTAIN DATE?

    I understand you very well buddy.
    It s always pity if the laptop is not working properly and if something needs to be replaced.

    I think there is a reason for the delay and I recommend you contact the ASP in Italy once more in order to clarify this matter.

  • Ive been waiting for 20 minutes waiting for the consultant to apple. Must be a lot of problems apple these days

    Ive been waiting for 20 minutes waiting for the consultant to apple. Must be a lot of problems apple these days

    A twenty minute wait is not at all unusual.

  • Should I buy a MacBook Pro now or wait for the WWDC

    Hello

    Well, I want to buy a MacBook Pro (my first one ever). However, I have read on some sites there is a new version of the MacBook Pro this year (at WWDC).

    Now I'm totally confused. I want to use a MacBook Pro 15 "(8 Go de RAM et 552 Go SSD) to work on large data / Business Intelligence technologies and programming."

    But I don't know if I have to wait for these new features or go ahead and buy this one now. And if these new features will be most useful for what I want to do.

    Thanks in advance.

    Apple has specifically discourages discussions on these forums about what and when the new products will be introduced and what changes there may be.

    The best advice is, what your needs are and this current model meets the.  If so, buy it, if not, don't buy it.   My observation of past changes in the introduction of new models is that the changes are incremental, not radical.  My primary MBP is a 2011 model (with 16 GB of RAM and an SSD hard drive) and I still do not feel outclassed by the current culture.

    Ciao.

  • waiting for device root

    Hello

    I'm getting the "waiting for root device" when trying to boot from a bootable usb key. Is this a problem with my hard drive or usb key. The mbp does not charge beyond that, so I'm not able to use the utility disc or AHT.

    The mbp needs a disc hard work to be able to boot from usb?

    Thank you

    Donny

    a MBP A1150 is a 15 "2006 MBP.  It will support the maximum OSX 10.6.8 is suggesting to your profile is already installed.  If the USB Installer is a more recent OSX, it can not be installed in your MBP.

    Ciao.

Maybe you are looking for

  • my iphone keeps restarting randomly 5s

    HI, so my iphone 5s just started rebooting randomly. wouod screen turns blue, then turn off and restart. I've also updated my phone to ios 9.1 last night. I got my phone taken far sunce August and I just returned it yesterday but this thing restart j

  • error 0 x 8001010108

    Unable to find that my pictuces on my drive of sam error 0 x 8001010108 want to do

  • CD images to the computer files

    How to copy photos from a CD to a file on your computer?

  • laptop slow, freezes and "unresponsive".

    Hi my laptop with Vista home premium, is very slow, continually freeze and "does not" to the point where it is almost impossible to use. I followed responses to similar issues dealt with on this forum and have run the sfc/scannow in cmd. It made me k

  • OfficeJet to 8600 more to the Wifi printer booting do not

    My printer suddenly stopped the initialization of the WiFi antenna when turned on.  I have not changed any drivers or software that would affect the State of the equipment installed. The WiFi feature worked two days ago. I keep the printer off when n