Problem with waiting-task

I tried automating the resetting of a lab with PowerCLI environment. This lab consists of 15 sets of 3 virtual machines. Each game contains a XP and a 2008 server a Linux device. Virtual machines created from templates and are assigned to specific user names. Automating this process would seriously help the technicians whose responsibilities

The script (which is listed below) has the following functions created and work:

(1) DeleteOldVMs - stop existing virtual machines and then deletes them from the disk

(2) CreateVMSet - creates each of the 3 virtual machines is necessary for each user.

(3) StartNewVMs - start all VMs newly created

(4) AssignUserToVM - assign rights to the VM assigns to each user

My last problem is the duplication of the task of start-VM and tasks of New - VM. New - VM task must finish before I assign rights to virtual machines and start them. I tried to use Wait-task, but I had no luck. I currently have the Wait-job sections deleted by the script. I'm looking for any suggestions on how I can properly implement Wait-task force the script to wait for that VM sets are created before proceed.

My only other thought was using Start-Sleep for a predetermined period.

Any thoughts?

Here's the script:

Function AssignUserToVM

{

$xpvm = get-vm WinXP-$n

$winvm = get-vm -Win2008 $n

$vistavm = get-vm OpenVista-$n

#$emrvm = get - vm Avogadro - $n

New-VIPermission -Entity $xpvm -main "sound$ n ' -role EHR822VirtualMachineUser -spread $false

New-VIPermission -Entity $WinVM -main "sound$ n ' -role EHR822VirtualMachineUser -spread $false

New-VIPermission -Entity $vistavm -main "sound$ n ' -role EHR822VirtualMachineUser -spread $false

#New - VIPermission - $emrvm - main entity "sound$ n '-role EHR822VirtualMachineUser-spread $false

}

Function CreateVMSet

{

#Create XP VM

$XPTemplate = Get-model -name 'model-WinXPPro.

$XPSpec = Get-OSCustomizationSpec -name "Windows XP."

$XPVMName = "WinXP-$n.

New-VM -VMHost "$VMhost" -name '$XPVMName' -model '$XPTemplate' OSCustomizationSpec - $XPSpec -location $VMLocation

VM #Create 2008

$2008Template = Get-model -name 'model-Win2008-32.

$2008VMName = 'Win2008-$n.

$2008Spec = Get-OSCustomizationSpec -name "Windows Server 2008".

$VMhost = Get-VMHost

New-VM -VMHost $VMhost -model $2008Template -name $2008VMName -OSCustomizationSpec $2008Spec -location $VMlocation

OpenVistA VM #Create

$OpenVistATemplate = Get-model -name 'model-OpenVistA-device.

$OpenVistaVMName = "OpenVista-$n.

New-VM -VMHost $VMhost -name $OpenVistaVMName -model $OpenVistATemplate -location $VMlocation

}

Function StartNewVMs

{

Start-VM -VM "Win2008 *-

Start-VM -VM "WinXP-* '.

Start-VM -VM "OpenVista *-

}

Function DeleteOldVMs

{

Stop-VM -VM "Win2008 *-

Stop-VM -VM "WinXP-* '.

Stop-VM -VM "OpenVista *-    

Remove-VM -VM "Win2008-* ' -DeletePermanently

Remove-VM -VM "WinXP-* ' -DeletePermanently

Remove-VM -VM "OpenVista-* ' -DeletePermanently

}

Write-Host "" Please enter your credentials to the announcement: "."

$vCenterCredential = Get-Credential

$VMhost = "hitecvsphere.ccbcmd.edu".

$vCenter = "hitechvcenter.ccbc.ccbcmd.edu".

$VMlocation = "AHL822".

Se connect-VIServer -Server $vCenter -Credential $vCenterCredential

$NumVMsToCreate = Read-Host "" enter the number of games of virtual machine that you want to create: "."

DeleteOldVMs

$n = 1

While ($n - the $NumVMsToCreate)

{

CreateVMSet

$n ++

}

StartNewVMs

$n = 1

While ($n - the $NumVMsToCreate)

{

AssignUserToVM

$n ++

}

Yes, because the virtual machine is always created when the task of waiting already get the signal that the task is complete.

Have you tried inserting a "sleep 30' for example?

BTW, using the - RunAsync on the New - VM, immediately followed by a waiting task for this New - VM cmdlet, is in my opinion the same as New - VM running without the RunAsync parameter and not using the Wait-job cmdlet.

The real value, IMHO, to use the RunAsync parameter is when you launch a bunch of New - VM cmdlets, and once they are all running start you a waiting task loop. See my post on Async tasks, the Get-job cmdlet and a hash table for an example of what I'm trying to say here.

Tags: VMware

Similar Questions

  • problem of waiting-task

    I have a script that updates the hba firmware. I wan't first to put the server in maintenance mode.

    $task1 = get-vmhost esx1.example.com | State game-vmhost-interview

    waiting-task-task $task1

    I get a:

    Waiting-Task: cannot bind parameter 'task '. Cannot conver esx1.example.com to 'Vmware.VimAutomation.Types.Task '.

    How to properly use Wait-task

    There are a few problems reported with waiting-task in the past.

    You can try the EnterMaintenanceMode_Task method.

    $esx = Get-VMHost  | Get-View
    
    $taskMoRef = $esx.EnterMaintenanceMode_Task(0, $true)
    
    $task = Get-View $taskMoRef
    while ($task.Info.State -eq "running" -or $task.Info.State -eq "queued") {
      sleep 2
      $task = Get-View $taskMoRef
    }
    
  • Problems with 'Wait-mission' and 'CloneVM_Task' in the script of vm - backup.ps1

    Hey all,.

    I hope you can help me with something. An environment that I help standing needs a systematic clone (copy) large number of virtual machines from a data store to another for customer test scenarios.

    Not being is not a type of programmer, I found a script that looks like it fits the Bill here: http://www.mbnbusiness.co.uk/blog/2010/08/updated-powercli-vmware-vm-backup-script-v2-0/

    However, when I run the script, I have two errors that seem to keep me from moving.

    (1) the first issue seems to revolve around the wait-job command.

    Waiting-Task: cannot bind parameter 'task '. Cannot convert the 'work-task-425″ type value 'VMware.Vim.ManagedObjectReference' to type 'VMware.VimAutomation.Sdk.Types.V1.Task'. C:\vmbackup\vm-backup.ps1:275 tank: 34
    + Wait-Task < < < < $task
    + CategoryInfo: InvalidArgument: (:)) [waiting-Task], ParameterBindingException)
    + FullyQualifiedErrorId: CannotConvertArgumentNoMessage, VMware.VimAutomation.ViCore.Cmdlets.Commands

    (2) the second issue is the creation of clones themselves. I see no error thrown in the PowerCLI console while the creation of clone, but I see errors indicating in vCenter:

    Clone the virtual machine

    VCE-bvm-30_sub

    Has specified parameter was not correct.  Home

    Any help you could provide would be most appreciated. I have attached the script, the input file and the error of console output.

    Thank you!

    Hi Aaron,

    (1) the problem here is that the variable $task contains an object of type ManagedObjectReference. It is essentially the task ID, while the Wait-job cmdlet waits for an object of type Task. What you need to get the object by its task ID and pass it to the Wait-job cmdlet. Put this befeore the line of the "Wait-Task $task" line: "$task = Get-job | "where {$_.id - eq $task}.

    (2) you do not specify a valid host in the $cloneSpec that you pass to the CloneVM_Task operation (' $vmView.CloneVM_Task ($cloneFolder, $cloneName, $cloneSpec) "). Set the it to the host where you want to place the cloned VM (by setting the property $cloneSpec.Location.Host). The host parameter can be set in certain situations, you need to decide based on the configuration you. Here is the description of the host of the VI QAnywhere parameter:

    The target host for the virtual machine. If not specified,

    • If the resource pool is not specified, current host is used.
    • If the resource pool is specified and the target pool represents a stand-alone host, the host is used.
    • If the resource pool is specified and the target pool represents a DRS cluster enabled, a host selected by DRS is used.
    • If the resource pool is specified and that the pool of the target represents an active without DRS cluster, an InvalidArgument exception thrown.

    I hope this helps.

    Kind regards

    -Angel

  • Problems with MAX tasks on different stand-alone

    Hallo!

    I have problems with my MAX-tasks and my V12 Dasylab on different stand-alone.

    I have 3 devices on the first PC.

    OR USB-6009 dev1

    NEITHER USB-6210 dev2

    NEITHER USB-6501 dev3

    Now, I had programmed a file Dasylab which uses the device 2 and device 3. Everythink worked fine. I exported my MAX configuration for unit 2 and unit 3 and imported on the second PC. But that Dasylab was not able to find the right tasks for my program on the second PC, even if MAX everythink that went well. The only solution was to delete all tasks and create them again. But then I tried to open the program stored on my first PC again and I had the same problem, Dasylab was not able to find the right tasks, only solution was to remove the stains and create them again. I tried to reset the configuration of my Dasylab with the "Synchronize with MAX-configuration" option, but it wasn't succsessful. DASYLab gave an errormessage, not mentioning not what exactly is the problem.

    Can anyone help?

    Thank you very much and have a nice day.

    Hilby

    Hallo Hilby,

    I think it can be more that can be solved on the Forum of NOR. I think you should contact your local dealer and ask for help directly.

  • Problems with DAQmx - tasks missing when I run my application on another PC

    Hello

    I use a NI USB 6009 and my program use DAQmx and different tasks for the input and output signal.

    I created an application and I want to run this application on another PC, which doesn't have the development environment, but the runtime engine and installed MAX. This PC is connected to the NI USB 6009.

    Now, I have the problem that the tasks are missing on this PC and I get errors when I run the application.

    I wonder why these tasks are not put into the application automatically? What should I do now? Can I somehow export tasks in MAX and copy them to the other PC? Is not complicate it?

    Hi Johannes,

    Have you created your tasks of measurement and Automation Explorer?

    If this is the case, you must export the file of configuration of measurement and Automation Explorer and then import it on the other computer.

    With LabVIEW 2010, you can import a configuration via your Installer file, but I don't know if you can do it with LabVIEW 7.1

    Kind regards

  • I have a problem with the task host .exe.

    I have problems with slow stop caused by the task host. I downloaded the fix buy it will not be installed. I get a message that the update is not applicable to my computer. I have a Toshiba A105-S4384. Any suggestions on how to get the fix to install?

    If the hotfix is not installed, you can try compatibility mode. If you are still unable to fix, you can do a reinstall of windows and it will certainly solve the problems you are having.

  • Problems with db/task.xml

    Hello

    When saving a custom scheduled task, I used weblogic utility to import and export the task.xml at MDS file.
    At first, I exported the file/db/task.xml task.xml, up-to-date with my tasks details custom set. And then imported it back to MDS by using the weblogicImportMetadata utility.
    Updated the weblogic.properties file to change the to and from places too.

    The import was successful. To check the file, I exported the file again and found that the file was in the State it had before the update.
    Also, when I checked in MDS_PATHS there are several copies of/db/task.xml.

    What I'm missing here? How can I make sure that the file is properly updated.

    Thank you
    Stone

    Published by: stone on November 23, 2012 10:02

    1. how the task.xml file is related to plugin.zip

    Scheculded task xml a tag called "oracle.iam.scheduler.TestScheduler" that defines the java class name. Now, plugin.xml also have the tag ' that define the java class is how the task.xml file to locate class java via plugin.zip.

    2. If we create files with different names, how IOM identifies what file * task.xml refer?

    IOM identify automatically. Only thing to consider is that the name of the file must be the same as the name of the scheduled task, with the extension .xml. You must import the scheduled task in the Oracle Identity Manager MDS/DB schema namespace.

    So, always create a custom file to a custom scheduled task. It will be easy to maintain & manage.

    For detailed steps, find the links above

  • Problem with the task of control of model code - execution instance remains open

    Hi Experts

    We have some model mappings, for which we use some similar code with the model code BUILT_IN_CT model. Mappings to run successfully, but the task of control of model code seems to remain open. It's the same thing, even if I use the code model of control by default BUILT_IN_CT/CCT_ORACLE.

    To see if the control task remains open, I run the script...\dbhome\owb\rtp\sql\list_requests.sql, and I get the following output:

    ====================
    EXECUTIONS
    ====================
    ID of the audit. State of... Name... Date of... Owner...
    16_FLOW_CONTROL LOAN 260573 19 APRIL 11 10:15:16 OWBSYS

    As a solution to the problem, we managed to implement a custom task jdbc, in which we are to pick up instances of this task and then close them using the owbsys.wb_rt_script_util.deactivate_execution procedure.

    Anyone know the reason for this problem and if there is a solution for it, other then to implement a custom task to close the open instances?

    We use OWB 11 GR 2 on Windows.

    THX
    Your help will be much appreciated

    Yes, I see now the verification element hanging out in OWB, this looks like a bug in the OWB audit management, it should not be suspended. I don't think impact on behavior, he is a piece of dangling audit data that should not exist. You can raise a bug/SR?

    See you soon
    David

  • Strange problems with scheduled tasks

    Hello Microsoft community.

    I have a domain with many servers (windows Server 2003), and there is a database of oracle on one of them. I usually use a batch file to back up the oracle database, and I'm sure that this lot works perfectly.
    So I logged on the server that contains the oracle database and create a new weekly scheduled task to back up my database, and the timing worked well in the first day.
    The next day, I logged on the server to make sure that the backup works, but I found a sentence (cannot start) under the status column and (0x1) under the column last result.
    I tried to delete the task and create it again, but nothing has changed.
    I used both domain administrator account and the Local Administrator account, but nothing has changed.
    I tried to check the task when I connect and disconnect, but nothing has changed.

    The accounts that I used to create the task have the full control permissions on the source folder that contains the batch files so the destination folder that contains the backup files.
    The Task Scheduler service is set to automatic type and its status is started.
    Whenever I double click the backup batch file works fine, but the task still does that for a time.

    What should I do?

    Kind regards.

    Hello

    Windows server 2003 issues are managed by the Technet forums.

    http://social.technet.Microsoft.com/forums/WindowsServer/en-us/home?category=WindowsServer

  • Problem with the task of human and Service

    I have a process this work perfect until I have add a Service task using the DB adapter. When I add to this the human task does not end when I press any result in the list of tasks or ADF. Any help?

    With the help of example of Dan, there may be files located in \Oracle\Middleware\WLShome_11.1.1.7\user_projects\domains\SOABPMDomain\servers\*[SOA Server logs] * \logs, depending on how you have configured your environment.

  • Problem with human task

    Hi, I have a problem:

    When I put a human activity task component palette in my bpel project and I'm trying to create a task definition it opens properly management taskeditor but when I try to save I can't! It is said that its impossible to save the document because it cannot find the path specified... but I don't change anything! I made the task easier as I can...
    the strange thing is that, if I create a task definition in law on the on the application Navigator bpel project icon and I choseCreate the definition of human task, it seems to work...

    first of all - what version are you using? in both (10.1.3 and 11 g) it is possible to create the def straight out of the bpel process task (11 g, you will have the chance to choose / or create a new).

    Just curious - some spaces in the path of your project on the file system?

  • Problem with the Task Manager. The top of the window is absent, there is no button or ways to Exchange to treat the view. Any suggestions on what to do?

    I have not downloaded anything unusual recently

    This behavior can occur if the Task Manager is running in tiny footprint mode. If you double-click on the empty in the border around the tabs, Manager space tasks switches to this mode.
    To enable the task to his typical display mode Manager, double-click the top border of the window.  TaurArian [MVP] 2005-2010 - Update Services

  • Problem with the task of mapping the object status

    Hello

    There is a "Create User" task, which at the end gives the status of the object to set.
    There is a later task named "Update form" which, on the rejection, must restore the status of the Configuration object.

    I put in place this logic in the 'Mission to the mapping of object status' tab in the console Design.
    However, this change doesn't think. What is the best solution in this case?

    Kind regards
    SK

    Once the resource is implemented, you can only have three status

    Enabled, disabled and removed

    You can do it, commissioning or any other

    These status shows the status of the resource. Now, once the user get configured how it can be provisioning (failed). Perhaps some update fails, what does not mean that the user is not put into service.

    Yes, you can do work around that Gyan has suggested to you

    -nayan

  • My cool fonts does not work, how can I fix this problem with waiting for hours?

    Whenever I try to enter my cool fonts system stop loading, I have never enter my cool fonts.

    Hello

    1 - What do you mean you have never were able to use the cool fonts you referred post?
    2. where did you downloaded these fonts?
    3. how exactly you are trying to load?

    The following articles may be useful:
    How to change the appearance of items on the desktop in Windows XP
    http://support.Microsoft.com/kb/310543
    To change your window fonts
    http://www.Microsoft.com/resources/documentation/Windows/XP/all/proddocs/en-us/display_change_window_fonts.mspx?mfr=true

    Also, look for error messages in the event viewer. If you find error messages after return the exact error message so that we can help you better.

    Reference:
    Using the event viewer
    http://www.Microsoft.com/resources/documentation/Windows/XP/all/proddocs/en-us/snap_event_viewer.mspx?mfr=true
    Understanding of event viewer
    http://www.Microsoft.com/resources/documentation/Windows/XP/all/proddocs/en-us/event_overview_01.mspx?mfr=true
    Procedure to view and manage event logs in Event Viewer in Windows XP
    http://support.Microsoft.com/kb/308427

  • problem Windows vista task manager

    Hi, I seem to have a problem with my task manager. I bring it to the top using ctrl alt del, but I can't seem to more close. His is not the small boxes he used for upstairs, nor was it a cross to close. What should I do?
    Thank you

    Double-click inside the border of the Task Manager window.

    That it will bring to its normal functions.

    See you soon. Mick Murphy - Microsoft partner

Maybe you are looking for

  • Problem with making of titles appear in the video

    I try inserting a few titles in my video. I chose the title of base with an opacity of 100%, but its showing is not in the video. When I go to edit it, its says that I chose it etc. But it is not appearing during playback. Here is a screenshot. The w

  • My wirelss is always disabled and I can't seem to enable it

    My phone randomly allows himself and continues to work until I'm done with it and it goes into sleep mode that turns off my wirelss, and it comes back when I want to use the wirelss again. Any suggestions? My laptop is a hp pavilion dv6000 with a ser

  • iCloud with Windows synchronization problem

    iCloud syncs my photos from my PC, but for some reason fine any it never download my videos.  I can see my videos on icloud.com, but they don't ever upload to my PC.  I have no idea why this is... any ideas? I have an iPhone 5 and a PC running Window

  • Logic Pro 7.2 update cost?

    What price has been the Logic Pro 7.2 update? (American or British price will be...) When he came out to the origin? Thank you...

  • PC World says free battery for computer laptops toshiba - need info

    Hi, I bought a toshiba laptop from PC world 01/01/2008 & was informed by the Assistant if I signed with Toshiba online I can get a free battery pack. I just registered, but can not see information about this offer. No one knows about it? Thought I'd