PowerCLI

 View Only
  • 1.  PowerCLI ForEach-Object -parallel

    Posted Mar 05, 2020 09:33 AM

    So I was trying out the -parallel parameter of the new Powershell 7 Core, but it doesn't seem to be working with PowerCLI. Here is the simple snippet:

    Connect-VIServer "vcenter" -User "user" -Password "pass"

    Measure-Command{
        $vmArr = Get-VM
        $vmArr | ForEach-Object {
            Get-SpbmEntityConfiguration -HardDisk (Get-HardDisk -vm $_)
        }
    }


    I'm getting the following error:

    Get-HardDisk:

    Line |

       2 |          Get-SpbmEntityConfiguration -HardDisk (Get-HardDisk -vm $_)

         |                                                 ~~~~~~~~~~~~~~~~~~~

         | You have  modified the global:DefaultVIServer and global:DefaultVIServers system variables. This is not allowed. Please reset them to $null and reconnect to the vSphere server.

    Without the -parallel parameter it works fine.

    Versions: Powershell Core 7.0, PowerCLI 11.5



  • 2.  RE: PowerCLI ForEach-Object -parallel

    Posted Mar 05, 2020 09:36 AM

    The current PowerCLI version (11.5.0) does not support PowerShell v7.

    From the Compatibility Matrixes for VMware PowerCLI 11.5.0

    Supported Windows PowerShell Versions

    VMware PowerCLI 11.5.0 is compatible with the following PowerShell versions:

    • Windows PowerShell 4.0
    • Windows PowerShell 5.0
    • Windows PowerShell 5.1
    • PowerShell Core 6.x (for Ubuntu and macOS)


  • 3.  RE: PowerCLI ForEach-Object -parallel

    Posted Jun 01, 2020 08:46 PM

    Not sure if new thread is best, but I am now running into this same issue on supported version 12.0 .

    I have tried to scope the -server variable with using and global and it doesn't seem to make any difference.

    My use case is vmkping via esxcli to test if there any packet drops.

    $mgmtVMK = get-vmhostnetworkadapter -VMKernel | Where-object {$_.ManagementTrafficEnabled -eq $true}

            $mgmtIP = $mgmtVMK.IP

            if ($turboCore)  #powershell 7 check

            {

                $mgmtVMK | ForEach-Object -Parallel {

                    $vmk = $_

                    foreach ($ip in $using:mgmtIP)

                    {

                        $esxcli = Get-ESXCli -VMHost $vmk.VMHost -V2 -Server $global:DefaultVIServer

                        $param = $esxcli.network.diag.ping.CreateArgs()

                        $param.host = "$ip"

                        $param.interface = "$vmk"

                        $param.count = "2"

                        $pingResult = $esxcli.network.diag.ping.Invoke($param)

                        if ($pingResult.Summary.PacketLost -ne 0)

                        {

                            Write-HTML "<h3>$($vmk) on $($vmk.VMHost.Name) dropped a packet</h3>"

                            $PacketDrops += 1

                        }

                    }



  • 4.  RE: PowerCLI ForEach-Object -parallel

    Posted Jun 01, 2020 09:14 PM

    That is unfortunately exactly the same problem as the 1st entry in this thread.

    The -Parallel switch causes issues with how some of the global variables that PowerCLI uses are implemented.

    The Dev Team is working on a solution.

    In the meantime, upvote the idea to show that this is a critical feature in PSv7 for many PowerCLI users.



  • 5.  RE: PowerCLI ForEach-Object -parallel

    Posted Jun 01, 2020 09:15 PM

    I should, of course, provide a link to the idea Support for the PSv7 feature Foreach -Parallel