VMware Cloud Community
johndavidd
Enthusiast
Enthusiast

Using Connect-CIServer in a Start-Job

Has anyone been able to complete something like this? This works perfectly in a plain PoSh window but running in a Start-Job it never gets past the connect-ciserver. The job shows running and HasMoreData .. but again, never completes.

I'm using PowerCLI 5.1 Update 2 and Powershell  3.0 which is supported under my PowerCLI version.

Start-Job -ScriptBlock  {

    # Add PSSnapins

   

    Add-PSSnapin VMware.VimAutomation.Core

    Add-PSSnapin VMware.VimAutomation.Vds

    Add-PSSnapin VMware.VimAutomation.License

    Add-PSSnapin VMware.DeployAutomation

    Add-PSSnapin VMware.ImageBuilder

    Add-PSSnapin VMware.VimAutomation.Cloud

   

    Connect-CIServer -Server testcloud.cloud.com -User testuser -Password Test111

    Get-CIVApp

}

0 Kudos
8 Replies
jake_robinson_b
Hot Shot
Hot Shot

I attempted to multi-thread with Start-Job a while back, but was unsuccessful. I gave somewhat of a detailed account in this thread: http://communities.vmware.com/thread/296805

It obviously has to do with adding the snap-in, so if you used raw REST calls you should be able to achieve world domination…

For instance, instead of using the Connect-CIServer and generating N number of sessions, you can re-use the same session token for each thread.

Cheers,

Jake

Jake Robinson VCP, vExpert - geekafterfive.com - Twitter: @jakerobinson
0 Kudos
johndavidd
Enthusiast
Enthusiast

Jake,

Thanks for your response.... I'm not clear on exactly how you would do this. Any examples? I read through your post and couldn't come up with anything.

0 Kudos
johndavidd
Enthusiast
Enthusiast

To attempt what you are saying I took the current session ID of my connect-ciserver and passed it to the start job as an argument.... still nothing.

Start-Job -RunAs32 -ScriptBlock  {

    # Add PSSnapins

   

    Add-PSSnapin VMware.VimAutomation.Core

    Add-PSSnapin VMware.VimAutomation.Vds

    Add-PSSnapin VMware.VimAutomation.License

    Add-PSSnapin VMware.DeployAutomation

    Add-PSSnapin VMware.ImageBuilder

    Add-PSSnapin VMware.VimAutomation.Cloud

   

    Connect-VIServer testvc01

    Get-PowerCLIConfiguration

    Connect-CIServer testcloud.cloud.com -SessionId $args[0]

    Get-CIVApp

} -ArgumentList @($session)

The connect-VIServer and the Get-PowerCLIConfiguration process... but the script stops at Connect-CIServer

0 Kudos
johndavidd
Enthusiast
Enthusiast

Bumping this... anyone?

0 Kudos
CSIEnvironments
Enthusiast
Enthusiast

Hi,

I don't use jobs yet and I don't know how they work. But I got this to work as expected (I think):

Start-Job -ScriptBlock  { 

    # Add PSSnapins 

     

    Add-PSSnapin VMware.VimAutomation.Core 

    Add-PSSnapin VMware.VimAutomation.Vds 

    Add-PSSnapin VMware.VimAutomation.License 

    Add-PSSnapin VMware.DeployAutomation 

    Add-PSSnapin VMware.ImageBuilder 

    Add-PSSnapin VMware.VimAutomation.Cloud 

   

    $task = Connect-CIServer YOURSERVER -user USERNAME -password PASSWORD -wa 0 -ea 0

    Get-CIvApp "Test CIvApp"

  exit

}

Then I waited for it to finish:

Get-Job 23 | fl

Once I saw:

JobStateInfo  : Completed

Finished      : System.Threading.ManualResetEvent

InstanceId    : 905c99b0-3771-4ea0-9711-f14db2009916

Id            : 23

Name          : Job23

ChildJobs     : {Job24}

I ran this: Get-Job 23 | Receive-Job

Name                           Enabled      InMaintenanceMode    Owner

----                                -------            -----------------                    -----

Test CIvAPP               True               False                              system

Do you get the same result? I also got Get-CIvApp "Test CIvApp" | get-civm "MachineName" to return the info.

Cheers,

DeanH

0 Kudos
johndavidd
Enthusiast
Enthusiast

I attempted setting it to a $task variable along with your extra switches and no luck... never does the connect.

Any other ideas?

Again this works in both a powercli window and a plain posh window but will not work in a start-job. A connect-viserver in a start job works fine.

0 Kudos
johndavidd
Enthusiast
Enthusiast

It seems PoSH 3.0 is the culprit here... uninstalling that let me proceed with the job.

However, I need 3.0 installed for some of the added benefit. Any way to get around this?

0 Kudos
johndavidd
Enthusiast
Enthusiast

adding a -psversion 2.0 at the end of my start-job corrected it for me!

0 Kudos