locked
PS workflow parallel inlinescript import-module powercli RRS feed

  • Question

  • Hi,

    As the Title suggests, this is messy.

    What we would like use workflow for is:

    - take multiple snapshots in vCenter

    - make the workflow take parameters

    - import the module VMware.VumAutomation

    Considering all the rules and restrictions regarding workflows I wonder if this is even possible.

    (not taking snapshots in the example, just testing with Get-VM)

              

    workflow VMSnapshot{
    Param(
      [array]$servers
    )
        inlinescript
        {
            Import-Module VMware.VumAutomation
            $vCenter = "XXXXXXX.YYY.intra"
            Connect-VIServer -server $vCenter

            ForEach -Parallel ($item in $servers)  
            {  
                   Get-VM -Name $item | select name,memorygb
             }

        }
    }




    VMSnapshot -servers "server1","server2"

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

    That's the code.

    Now I know that you can't use -parallel inside inlinescript. This is just the "pseudo-code" explaining the functionality.

    How would one go about to make this work?

    Thanks

    /Daniel

    Friday, February 16, 2018 3:22 PM

Answers

  • Has to be done in this order:

    workflow VMSnapshot{
        Param(
            [array]$servers
        )
        ForEach -Parallel ($item in $servers){
            inlinescript{
                Import-Module VMware.VumAutomation
                Connect-VIServer -server "XXXXXXX.YYY.intra"
                Get-VM -Name $using:item
            }
        }
    }
    
    
    VMSnapshot $servers | select name,memorygb
    Of course a workflow is unnecessary unless you have hundreds of VMs.


    \_(ツ)_/


    • Edited by jrv Friday, February 16, 2018 3:41 PM
    • Marked as answer by Daniel Mercourios Monday, February 19, 2018 7:06 AM
    Friday, February 16, 2018 3:40 PM

All replies

  • Has to be done in this order:

    workflow VMSnapshot{
        Param(
            [array]$servers
        )
        ForEach -Parallel ($item in $servers){
            inlinescript{
                Import-Module VMware.VumAutomation
                Connect-VIServer -server "XXXXXXX.YYY.intra"
                Get-VM -Name $using:item
            }
        }
    }
    
    
    VMSnapshot $servers | select name,memorygb
    Of course a workflow is unnecessary unless you have hundreds of VMs.


    \_(ツ)_/


    • Edited by jrv Friday, February 16, 2018 3:41 PM
    • Marked as answer by Daniel Mercourios Monday, February 19, 2018 7:06 AM
    Friday, February 16, 2018 3:40 PM
  • Thank you! Worked as intended.
    Monday, February 19, 2018 7:07 AM