New-VM hangs over the background task

I am writing a script to automate some vm deployment and am having some problems with a background task.  If I run the code below, the new - vm command hangs and does not always complete the task.  I have to manually kill the jobs to get them to stop.  The next set of code below which is exactly the same thing, but not in a separate post and it works fine.  I am running the script on a windows 7, Powershell 3.0, esx server 5.1, 5.5 powercli. Any ideas? I have attached two scripts below as well. Any help would be appreciated.

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

#********************Add Snapin*************************

#Import module PowerCLI

Add-PSSnapin VMware.VimAutomation.Core

#Update the title bar

$host.ui.rawui.WindowTitle = "PowerShell [PowerCLI loaded Module] '"

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

#Declare high-level Script Varibles

$vcserver

$userName

$SecurePassword

$connectionUp = 0

$Credentials

While (0, $connectionUp - eq)

{

Variable #Set for Vcenter connection

$vcserver = Read-Host "Vcenter Server you want to connect to?

$userName = Read-Host "enter user name".

$SecurePassword = Read-Host-Prompt "enter password" - AsSecureString

$Credentials = new-Object System.Management.Automation.PSCredential '

-ArgumentList $UserName, $SecurePassword

$connectionUp = 0

try {}

# Set all errors to be a stop action

$ErrorActionPreference = "stop".

#Connect to the vCenterServer

SE connect-VIServer-Server $vcserver - Credential $Credentials

$connectionUp ++

}

catch {}

#Connection failed

"Unable to connect".

$connectionUp = 0

}

#Set that all default return errors

$ErrorActionPreference = "continue".

}

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

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

#*** Menu variables *.

#Title and Message

$title = "deploy the virtual machine.

$message = "select Action".

#Creates menu options (new options should be added in the table down below)

$UsVm = new-Object System.Management.Automation.Host.ChoiceDescription '& US' "

"Creates US VM."

$Eu = new - Object System.Management.Automation.Host.ChoiceDescription '& Europe' "

"Creates the VM Europe."

"$exit = New-Object System.Management.Automation.Host.ChoiceDescription" & quit ","

"Exits Script."

#Creates the table of options

$options = [System.Management.Automation.Host.ChoiceDescription []] ($UsVm, $Eu, $exit)

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

Variable Loop #End

$running = 0

#Loops the Menu up to what the exit option is chosen

While ($running - eq 0) {}

#Creates the Menu object

$menu = $host.ui.PromptForChoice ($title, $message, $options, 0)

switch ($menu)

{

{0}

Machine virtual #Deploy U.S.

# Include variables for the virtual machine.

$vmName = Read-Host "what is the name of the virtual machine?

Start-Job - ScriptBlock {}

SE connect-VIServer-Server $args [2] - Credential $args [1]

$cluster = get-Cluster-name "VDI Workstations - VCA Sandy Bridge - (HA, DRS)"

$template = get-Template-name "ViewWin7Template".

$custSpecifacation = get-OSCustomizationSpec-name 'Standard of Windows 7 desktop.

$dataStoreCluster = get-DatastoreCluster-name of 'VDI SAN Production'

$location = get-file-name 'Mobile computers to office (MD).

$DeployVmName = $args [0]

$DeployedVmName = $DeployVmName

New-VM-name $DeployedVmName - location $location - model $template - ResourcePool Datastore - $dataStoreCluster - OSCustomizationSpec $custSpecifacation $cluster - slim DiskStorageFormat

Start-Sleep - s 60

Start-VM $DeployedVmName

} - InitializationScript {Add-PSSnapin VMware.VimAutomation.Core} - ArgumentList $vmName, $Credentials, $vcserver

}

1 {"you selected KAY."}

2 {$running = 1}

}

}

Here's the script according to which works very well

#Import module PowerCLI

Add-PSSnapin VMware.VimAutomation.Core

#Update the title bar

$host.ui.rawui.WindowTitle = "PowerShell [PowerCLI loaded Module] '"

#Declare high-level Script Varibles

$vcserver

$userName

$SecurePassword

$connectionUp = 0

$Credentials

While (0, $connectionUp - eq)

{

Variable #Set for Vcenter connection

$vcserver = Read-Host "Vcenter Server you want to connect to?

$userName = Read-Host "enter user name".

$SecurePassword = Read-Host-Prompt "enter password" - AsSecureString

$Credentials = new-Object System.Management.Automation.PSCredential '

-ArgumentList $UserName, $SecurePassword

$connectionUp = 0

try {}

# Set all errors to be a stop action

$ErrorActionPreference = "stop".

#Connect to the vCenterServer

SE connect-VIServer-Server $vcserver - Credential $Credentials

$connectionUp ++

}

catch {}

#Connection failed

"Unable to connect".

$connectionUp = 0

}

#Set that all default return errors

$ErrorActionPreference = "continue".

}

$vmName = Read-Host "what is the name of the virtual machine?

$cluster = get-Cluster-name "VDI Workstations - VCA Sandy Bridge - (HA, DRS)"

$template = get-Template-name "ViewWin7Template".

$custSpecifacation = get-OSCustomizationSpec-name 'Standard of Windows 7 desktop.

$dataStoreCluster = get-DatastoreCluster-name of 'VDI SAN Production'

$location = get-file-name 'Mobile computers to office (MD).

$DeployedVmName = $vmName

New-VM-name $DeployedVmName - location $location - model $template - ResourcePool Datastore - $dataStoreCluster - OSCustomizationSpec $custSpecifacation $cluster - slim DiskStorageFormat

Start-Sleep - s 60

Start-VM $DeployedVmName

Have you ever tried adding the line Add-PSSnapin the scriptblock in the 2nd script.

Another problem could be that the script sends messages of 'warning', and these may cause crashes in tasks in the background as well.

Try to set $WarningPreference = "SilentlyContinue".

Tags: VMware

Similar Questions

  • Some random windows remain in front - new windows open in the background

    Hello

    I have a very annoying and recurring question: one or more windows of my session always remain at the top of others. She does not always affect the same software (I've experienced with Chrome, Visual Studio, Windows Explorer, MS Word, MS Excel, notepad...). Sometimes a single window is affected, sometimes 2 or 3 (as 1 word document, chrome and 1 explore window). I think this is a Windows problem, because it is not logical that all these software would default at the same time, with no repeatable behavior.
    If I open a new window (Notepad, calculator, internet room to connect to this Internet site, Panel, etc) it will be displayed in the background, so the only way that I have to see him (or even know it's here) is to reduce all windows until I find the one I want. If I select using the bar of tasks, or alt + tab, it presents in the face, but as soon as I let go of the mouse button / key, windows 'stay face' returns. If I drag a new window to a position of the screen where a defective window, he is dragged behind it (even if I focus on that).
    I first thought that I had a session corrupted, so I created a new one with the new username etc, but the problem is the same. I did some research and it seems to be a well known since Win98 problem, so I tried several "tricks" supposed to work (change the behavior to 'combine' or 'lock' bar tasks, use/not use aero peek, remove all software pointing device running, run a windows update, change the ForegroundLockTimeout setting...). Either the "fix" doesn't work at all, or it does for only 20 to 40 minutes (just enough for me to notice it's gone and you can enjoy the normal use of a computer...), before returning.
    I hope my description is clear enough for you, the experts to understand what the problem is and give me a solution.

    Hello

     
     
    I also suggest you to download and run the latest Microsoft Scanner on your computer and check to see if it helps:
     
    http://www.Microsoft.com/security/scanner/en-us/default.aspx
     
    Note:
    data files that are infected must be cleaned only by removing the file completely, which means there is a risk of data loss.
  • Bought new Moto360 hangs on the update.

    Not happy, this is what happened today:

    -Unboxed my new bike 360

    -It started to download update.

    -J' downloaded android app on my Nexus 5 wear

    -seems to have synchronized well enough.

    -360 restarted motorcycle stopped at 30% and displays a picture of the android robot green on the back with his chest open and a red exclamation point! above it...

    -After some time, 360 motorcycle restarts and sits at a loading animation, and says 'just a minute... "forever...

    continues to do little matter what I try.

    Have yet to see the cards and screensavers, because you cannot find past this part.

    What should I do to fix this?

    Some advice I found on another site

    Now after yesterday and saw many still go through it today, I thought it would be a good idea to send out a message of PUBLIC interest about how to solve these problems.

    LOADING PROBLEMS

    When you set up the 360, there seems to be some kind of service that runs in the background that eats battery life quickly. If you have not yet completed the putting up of your watch, you will see that even when it is docked your watch will lose the battery charge. It's normal, your watch is not defective. To fix - turn off your watch and let, it loads about 80 percent while only off (preferably 100%). Then finish the installation process. Once you can see your watachface your 360 will start loading as usual.

    Note: for me the Watch has always tried to restart. Keep an eye on it and keep turning backwards as if it turns on it will start to drain again

    'JUST A MINUTE' OR 'WITHOUT INTERNET' QUESTIONS

    There is a firmware update that the watch needs to install before being fully functional. To install this it needs a lot of battery power (some say 80%, I got mine to work 60% last night). If you do not have enough battery for this update run, you will be able to set your language and link your phone, but chances are that you will be stuck in a circle of green rotation with 'Just a Minute' on the screen. If you let it run long enough it displayed an error 'No Internet'. Follow the support questions and let it load everything off until it gets to a point where the update will install. Then you should be good!

    Note - once he gets enough power, if it still does not work you probably need to reset your watch. I've done a few times

    WATCH DOES NOT RESET

    This one is a little off the walls, but it is something that I also met. When you go to reset your watch (press and hold the power button until settings appears, and then choose 'Reset') a screen will appear asking you to confirm the reset. If your watch is anything like mine, when you press to confirm the reset, nothing happens. You can type as many times as you want and it just sits there. In this case, just wait. Even if it is not an answer immediately or indicate that it worked, your watch should restart in a few seconds(10ish?). When he comes back up you will see the circles to carry Android during the reset process. Then it will restart and you will be on the screen Set Language.

    I hope this helps some of you who have the same problems as me. I almost went to Best Buy to return/exchange the watch thinking it was broken when really it could be fixed here at home. If you want to add me something to this let me know and I'll do it, if not good luck for your watch running. Once it's good, you'll love

    From swimbikerunrun:

    Two more things here that I found when you work with a support technique moto:

    1. App is stuck on 'just a minute...' On your phone, go to settings--> Apps--> stop the strength to carry Android, clear data (might have to do it twice) clear the cache



  • Battery keeps dying before put you in place, even if you it reboot: take Android and click on the button to disconnect your 360 motorcycle. Who's going to say on the phone to stop trying to connect.



  • Enable the developer menu: menu-> about market-> Build-> tap as x 10

  • I would also add that if the deletion of your data and disconnect do not help, I found this goin

  • task host window is prevents the background tasks

    When I open my laptop it says windows task host stop background tasks

    Hi Aditya,

    Thanks for posting your question in the Microsoft Community. You seem to have a problem with the computer in normal mode. We will help you in the matter of fixing. Please answer the following questions to help me understand the issue better:

    1. What is the brand and model of the computer?

    2. You did changes to the computer before this problem?

    The question may be die for applications or corrupt display driver conflict. Refer to the following suggestion and check the status of the issue.

    You can check the suggestions I give the following link and check if that helps fix the problem.

    http://answers.Microsoft.com/en-us/Windows/Forum/windows8_1-performance/task-host-window-is-stopping-background-tasks-is/08b48a9d-a657-4e4e-9494-bc43553e9bf2

    Important: System Restore will return all system files not as documents, email, music, etc., to a previous state. These files of types are completely affected by the restoration of the system. If it was your intention with this tool to recover a deleted file to non-system, try using a file instead of system restore recovery program.

    Hope this helps you, please let us know if you need assistance.

  • Tabs hang in the background and update to the opening

    I had this problem since I upgraded to 29 on Firefox for Mac. When a tab is open in the background for a while, it suspends the sort of himself. The tab that is open in the foreground was never this problem, so I guess this has something to do with the tabs in the background. Now I use Firefox Sync on all my devices and use the latest version on each device, and any other device has this problem. I sync everything, including the addons, so if an add-on cause, it must have caused this on my other devices. Now, when one of these tabs is suspended and that I click on it, I see a blank page, and then the tab starts refreshing. It's pretty boring. I don't even have tabs open these days. Any ideas of what could be the cause?

    Yes, one of my extensions. I was so stupid. I had a tab called extension stop installed. Do not install, but yes, had installed and he suspended background tabs. So, Yes. Just disabled it and the problem is solved.

  • Shutoff valve 3G / 4G to stop the background task using data

    Android enabled me to shutoff valve 3G / 4G, except when I wanted it on.  This controlled use of unwanted applications as data updated in the background.  I want to really just phone and text except when I need data services.

    You can turn off the cellular data settings. Disabling the LTE (4G) and 3 G without disable cellular data will stop all data usage. If cut you 4G and 3G, the phone will come down to the network EDGE (2G) if it is available. It will always use data, just more slowly.

  • System freezes and the background task bar disappears completely when right clicking on start / Explorer.

    When I right click on the lower left button 'Start', then click on "Explore", the system hangs with the files not listed only partially, and the bar at the bottom of the screen disappears completely. I can not stop the system normally, but eventually must do so by pressing the power button on the computer.

    A VIRUS CAN DO ON YOUR COMPUTER... IF U R ABLE TO CONNECT YOUR PC TO THE INTERNET, TRY A SCAN ONLINE THAT IS FREE OF MOST OF THE ANTIVIRUS SITES.

    OR TRY RESTORING THE SYSTEM THROUGH SAFE MODE

  • Get new tabs to display the background instead of a new window next to the original window.

    I have Vista and barely installed explore 9.  I can't click on a link in a window, and it still load in another window next to the original window instead of a new tab at the bottom (near the Start button).  I researched and tried many different combinations of tools, internet options, settings.  Someone please help!

    Hi Vickie,

    Go ahead and uncheck (similar group task buttons) that should allow it to work properly.

  • Failed to set the new CSS rule for the background image

    Hello

    Maybe I've finally lost my mind... I myself find it impossible to add a background image to the header of my project portion.  I select the "header" in the property Panel section, click on "add a new CSS rule.  Curiously, DW does not in the name of the selector for me, which is probably an indication that something is wrong, but I don't know what.  I went through the steps of filling in the name of the switch by hand, choose the .jpg file and setting is like a background image, but he never takes.

    There has got to be something simple that experienced users of DW can explain.  Go ahead, experts, you out there?

    Thank you...

    When things go south, it is almost always caused by a mistake of small coding somewhere.

    Unbalanced tags are the usual suspects.

    Run validation and fix the errors reported.

    Nancy O.

  • CS5-> CS6 upgrade hangs, block the windows Task Manager, does nothing else

    Got the CS6 Design Standard update, hoping to upgrade from CS5 Design Premium. Could it be the problem? I don't have all the added bonus and this stuff is ridiculously expensive.

    In any case, I put the disc, nothing happens. I run the set - up.exe, the disc spins, then nothing continues to happen. I watched it for up to 5 minutes and nothing.

    Set - up.exe isn't in Applications, but it's in the process in windows Task Manager. However, there is no real activity at all. When I try to end the process, WTM crashes. I have to every hard reboot or eject the disc in order to recover.

    What gives? I can post PDApp.log if need be, but I don't know how much help it will be.

    W7 Pro 64-bit

    So it turns out that it was the reader. I installed an internal DVD SATA drive and it ran the update without fault. Just in case someone else stumbles across this post with a similar problem, make sure that you do not install the update of an external USB DVD drive, specifically a Samsung SE-S084. It won't work.

    Thanks for the help guys!

    J

  • Automation of the new VM in the background (as the task or work)

    Hello guy

    Need you help again...

    I am trying to automate the creation of virtual machines. but to do this in the background, I played with the Wait-task and the Start-Job cmdlet, but didn't success to make it work.

    The script change a customization specification, create the new virtual machine, game - vm with cpu/memory settings, updated hot hot-plug/add settings and turn on the virtual machine, looks like this:

    Get-OSCustomizationSpec $NewVM_OSCustomizationSpec |
    Get-OSCustomizationNicMapping |
    Game-OSCustomizationNicMapping - IpMode: 'UseStaticIP' - the $NewVM_Ipaddress IpAddress
    SubnetMask - $NewVM_SubnetMask - passerelle_par_defaut $NewVM_Gateway '
    DNS - $DNS

    $NewVM_OSCustomizationSpec - FullName $NewVM_ServerName
    "New-VM-name $NewVM_ServerName-model $NewVM_Template"
    -VMHost $NewVM_ESXHost - Datastore $NewVM_Datastore '
    OSCustomizationSpec - $NewVM_OSCustomizationSpec-location $NewVM_Folder #-RunAsync

    Set-VM - $NewVM_ServerName NumCpu VM - $NewVM_CPU - MemoryMB $NewVM_RAM-confirm: $false

    $VM = get - VM $NewVM_ServerName
    $Spec = new-Object VMware.Vim.VirtualMachineConfigSpec
    $Spec.memoryHotAddEnabled = $true
    $Spec.cpuHotAddEnabled = $true
    $Spec.NumCoresPerSocket = 1
    $VM. ExtensionData.ReconfigVM_Task ($spec)
    Start-VM $VM

    My problem is that if I run the game - vm until the task of the new vm is complete, of course, it doesn't, I need to set up tasks for work one by one, after waiting each task to be completed before starting the new task, but to him everything in the background,

    Please help me if you can.

    Thank you very much, I appreciate all the help

    I suspect that the background task may be waiting for something.

    Try to disable the warnings to begin with, add the following line at the top of your script block Start-Job.

    $WarningPreference = "SilentlyContinue".

    BTW, have you given up on the RunAsync?

  • Background tasks repeated on the PlayBook?

    Hello!

    I need to know if there is a way to implement a background task repeating for the PlayBook within a WebWorks app? I've used the search function, but it seemed that this is not possible, but I can't believe that.

    Is there a chance to make any kind of workaround or mix things (maybe have a code in the application, as well as native code webworks or something else)? If Yes, could you do a picture what needs to be done to get the background tasks repeated work?

    Thanks in advance.

    See you soon,.

    Sven

    Hi Sven,

    I think we've covered this broad already via Twitter, but I wanted to answer for others here in the forums.

    Currently the Tablet OS does not support background tasks.  Features of the application can run only during the execution of the application itself.

    To achieve something as a data synchronization, I would recommend this doing in the background while the application is open and during its lifecycle from start-up. This can be accomplished by using async XmlHttpRequest and perhaps even the Web workers?

    See you soon,.

    Adam

  • Liaison and background tasks

    Hello

    I'm new to Java FX. I decided to give it a try after the liberation of Netbans 7.1 and I consider it seriously for a project in hand.

    I started something following the blog of Richard Bair: http://fxexperience.com/2011/07/worker-threading-in-javafx-2-0/
    and also the File Downloader demo at: http://code.google.com/p/jfxee/source/browse/trunk/jfxee8/src/main/java/com/zenjava/download/
    But I'm having a problem here.

    The code below is a simplified version of the problem I have. I tried a number of other variants. The problem is, he can't make it "twice" and the background task is suspended. No exception is thrown. Cannot display the label 'a In other variants, well that I saw the update to reach etiquette and showing 'a', but it still hangs just after it.

    If I use updateMessage() or updateProgress() then they work like a charm, but I finally wish to pass some more complex data of my background. The code example uses a string, but finally I use ObjectProperty < T > where T will be a class of mine or maybe a collection of strings.

    What can be wrong here?
    Thank you
    -----------------------------
    SerializableAttribute public class BindTest extends Application {}
    Public Shared Sub main (String [] args) {launch (args) ;}

    {} public void start (point primaryStage)
    bar final label = new Label ("status");
    Root VBox = new VBox();
    root.getChildren () .add (bar);
    primaryStage.setScene (new scene (root, 300, 250));
    primaryStage.show ();

    the last task of ConnectTask = new ConnectTask();
    New Thread (task) m:System.NET.HttpListener.start ();
    bar.textProperty () .bind (task.fooProperty ());
    }

    private class ConnectTask extends task < vacuum > {}
    private string foo = new SimpleStringProperty();

    protected Void call() throws Exception {}
    Logger.info ("setting once");
    foo.setValue ("one");
    Logger.info ("defining twice");
    foo.setValue ("two");
    Logger.info ("set thryce");
    foo.setValue ("three");
    Returns a null value.
    }

    public final String getFoo() {}
    Return foo.get ();
    }

    public final void setFoo (String value) {}
    foo.setValue (value);
    }

    public string fooProperty() {}
    return foo;
    }

    }
    static Logger logger = Logger.getLogger (BindTest.class.getCanonicalName ());
    }

    Please wrap your code in the code of {tags} when the assignment makes it easier.

    Your call is in a background thread, you want to do an update in the JFX Thread (FXT). updateProgress done automatically for you, but for more complex values, to do a little work yourself. Richard works on improving the API of tasks to do this (next version I think) but in the meantime:

    protected Void call() throws Exception {
    
            // do some slow background stuff (I'll just sleep for fun)
            Thread.sleep(1000); 
    
            Platform.runLater(new Runnable() {
                public void run() {
                    // this is on the JFXT so you can update your values
                    logger.info("Setting once");
                    foo.setValue("one");
                }
            });
    
            // do some slow background stuff (I'll just sleep for fun)
            Thread.sleep(1000); 
    
            Platform.runLater(new Runnable() {
                public void run() {
                    // this is on the JFXT so you can update your values
                    logger.info("Setting twice");
                    foo.setValue("two");
                }
            });
    
            // do some slow background stuff (I'll just sleep for fun)
            Thread.sleep(1000); 
    
            Platform.runLater(new Runnable() {
                public void run() {
                    // this is on the JFXT so you can update your values
                    logger.info("Setting thryce");
                    foo.setValue("three");
                }
            });
            return null;
    }
    
  • How to change the background color of the code written DW page but not the Web page...

    How to change the background color of the code written DW page but not the Web page...

    If you have DWCC2015, you can change to edit > Preferences > coloring Code and either choose a new theme (RecoGnEyes is the background dark code by default) or you can change it to what you want in the background field by default.

    2014 CC had no theme options, but you can change the background color in the same place.

    I think that some of the previous versions also had the option, but I don't have them on my machine to check.

  • Background task alert

    I am spawning my own threads to perform a task. I followed the thread in the task of inactivity at regular intervals, to see if the wires have been completed or not and get an update. Now my problem is,

    I would like to see Indesign leave until my task is completed. I prevent users to quit smoking by throwing a CAlert, that takes away control of my idle task.

    My question is, is there an alert of background (such as the reference in the programming guide) to page 127 so that I can keep my son of surveillance and close the dialog box once the process is complete?

    "

    Background threads cannot directly report to the user on the progress, success or errors. These are some

    presented in the background tasks Panel. In addition, an animation is displayed in the application bar when

    background tasks are underway and an background task alert may appear when a background task

    He must convey a message to the user.

    "

    Such background task is displayed when a user tries to leave indesign and itself is removed when the task is completed, as this. Is there such an API exposed to third-party developers?

    Define dialogue en and then passing ' dialogue IDialog * = dialogMgr-> CreateNewDialog (dialogSpec, IDialog::kModeless); "solved the issue.

Maybe you are looking for