PowerCLI

 View Only
  • 1.  foreach-object -Parallel in powerCLI

    Posted Mar 14, 2023 03:02 PM
      |   view attached

    Hi ,
    I try to run simple script of foreach-object parallel from : https://blogs.vmware.com/PowerCLI/2021/02/new-release-vmware-powercli-12-2.html

    running powershell 7 , with powercli 13 build - 20829139
    its look that nothing happened after running.
    i am trying 2 script:
    1-save the output to $listStorage.
    2- runinng the original script without results:

    $cred= Get-Credential
    $conn = Connect-VIServer testvcsa.cpbu.com -Credential  $cred
    Function Execute-WithoutPcliContext
    {
      $vmlist= get-VM
      $vmlist |ForEach-Object -Parallel {
         (Get-VM -Name $_.Name -Server $using:conn).Name
      } 
    }

    or

    $cred= Get-Credential
    $conn = Connect-VIServer testvcsa.cpbu.com -Credential  $cred
    Function Execute-WithPcliContext
    {
        $pcliContext= Get-PowerCLIContext
        $vmlist= get-VM
        $vmlist |ForEach-Object -Parallel {
            Use-PowerCLIContext -PowerCLIContext $using:pcliContext -SkipImportModuleChecks
            (Get-VM -Name $_.Name ).Name
        }
    }





  • 2.  RE: foreach-object -Parallel in powerCLI

    Posted Mar 14, 2023 04:45 PM

    Have a look at Example 2 on the Help page for the Use-PowerCLIContext cmdlet.