Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 168400

Re: Problem with PowerCLI and Threads / Jobs

$
0
0

Hi, that helped alot - thanks! Still I need some further assistance:

 

This is the script that starts the threads. In this case 5 at a time.

 

$job = {

        Set-Location $args[0]

        .\Deploy-VM.ps1 -session $($args[1]) -vcserver $($args[2]) -name $($args[3]) -clusterName $($args[4]) -folder $($args[5]) -template $($args[6]) -custSpecName $($args[7]) -numCPU $($args[8]) -memoryGB $($args[9]) -diskGB $($args[10])

}

 

$currentPath = (Split-Path -parent $MyInvocation.MyCommand.Definition)

$session = $global:DefaultVIServer | %{ $_.sessionsecret }

$vcserver = $global:DefaultVIServer.ServiceUri.Host

 

1..5 | foreach {

        $id = "{0:D3}" -f $_

        Start-Job -ScriptBlock $job -ArgumentList $currentPath, $session, $vcserver, "vd$id", 'cluster1', 'folder1', 'template1', 'custspec1', '2', '4', '50'

}

 

Get-Job | Wait-Job

Write-Host "Done!"

 

Used standalone, the Deploy-VM script works like a charm:

 

PowerCLI C:\> $session = $global:DefaultVIServer.sessionsecret
PowerCLI C:\> $vcserver = $global:DefaultVIServer.ServiceUri.host
PowerCLI C:\> $session
52143172-c2a1-2086-e52c-53a0bb772b85
PowerCLI C:\> $vcserver
vc1.lab.invalid

 

Now I clear the DefautlVIServer variable so that the script will try to reconnect using the provided session.

 

PowerCLI C:\> $global:DefaultVIServer = ""

 

Now I execute the script:

 

PowerCLI C:\> .\Deploy-VD.ps1 $session $vcserver vm1 cluster1 folder1 template1 custSpec1 2 4 50vc1.lab.invalid

 

Name                      Port  User
----                           ----    ----
vc1.lab.invalid          443   Administrator
Staring deployment process: 07/26/2013 16:42:30
Finding best Datastore ...
Cloning VM ...

....

 

The process runs through an everything is good. Now let me show you what happend when I do it the threaded way:

 

PowerCLI C:\> .\Deploy-5VDs.ps1

 

Id              Name            State      HasMoreData     Location             Command
--              ----            -----      -----------     --------             -------
1               Job1            Running    True            localhost            ...


PowerCLI C:\> Receive-Job Job1

 

Name                           Port  User
----                           ----  ----
vc1.lab.invalid          443   Administrator
Staring deployment process: 07/26/2013 16:50:15
Finding best Datastore ...
Cloning VM ...

 

Looks like everything is fine ... unitl:

 

PowerCLI C:\> Get-Job

 

Id              Name            State      HasMoreData     Location             Command
--              ----            -----      -----------     --------             -------
1               Job1            Failed     False           localhost            ...

 

PowerCLI C:\> Receive-Job Job1
Receive-Job : The background process reported an error with the following message: .
At line:1 char:12
+ Receive-Job <<<<  Job1
    + CategoryInfo          : OperationStopped: (System.Manageme...emotingChildJob:PSRemotingChildJob) [Receive-Job], PSRemotingTrans
   portException
    + FullyQualifiedErrorId : JobFailure,Microsoft.PowerShell.Commands.ReceiveJobCommand

 

PowerCLI C:\>

 

What's happening here??? I also get the message as shown in the attachement.

 

cheers

Mathias


Viewing all articles
Browse latest Browse all 168400

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>