PowerCLI

 View Only
  • 1.  cmdlet to obtain CRC errors on hosts

    Posted Jun 30, 2022 05:45 PM

    i see in one of the vmtn posts, this script that can get the CRC errors for a host

    $esxName = 'esx01'

    $esxcli = Get-EsxCli -VMHost $esxName -V2
    $esxcli.network.nic.list.Invoke() |
    ForEach-Object -Process {
    $esxcli.network.nic.stats.get.Invoke(@{nicname=$_.Name}) |
    Select @{N='VMHost';E={$esxcli.VMHost.Name}},
    NICName,PacketsReceived,PacketsSent,ReceiveCRCerrors
    }

     

    is there a way we can run a cmd like 
    get-cluster | get-vmhost | xxxxxxxxx | export-csv -noinformation -path xxxx -useculture

    basically, i am looking to get a dump into csv with these columns

    cluster| vmhost | NIC | receive CRC errors

    much appreciated



  • 2.  RE: cmdlet to obtain CRC errors on hosts

    Posted Jun 30, 2022 05:52 PM

    You could do something like this

    Get-Cluster -PipelineVariable cluster | 
    Get-VMHost -PipelineVariable esx |
    ForEach-Object -Process {
      $esxcli = Get-EsxCli -VMHost $esx -V2
      $esxcli.network.nic.list.Invoke() |
      ForEach-Object -Process {
        $esxcli.network.nic.stats.get.Invoke(@{nicname=$_.Name}) |
        Select @{N='Cluster';E={$cluster.Name}},
          @{N='VMHost';E={$esxcli.VMHost.Name}},
          NICName,PacketsReceived,PacketsSent,ReceiveCRCerrors
      }  
    } | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture
    


  • 3.  RE: cmdlet to obtain CRC errors on hosts

    Posted Jul 01, 2022 06:04 PM

    Hello LucD

    the above cmd runs for each esxi host i believe. would there be an amendment to fetch the cluster and run for all hosts?

    correct me if i am wrong 



  • 4.  RE: cmdlet to obtain CRC errors on hosts

    Posted Jul 01, 2022 06:49 PM

    The code runs for all ESXi nodes in all clusters



  • 5.  RE: cmdlet to obtain CRC errors on hosts

    Posted Jul 07, 2022 05:30 PM

    Hello LucD
    can you help on this error?

     

    PS C:\Users\xxx> Get-Cluster -PipelineVariable xxxx | Get-VMHost -PipelineVariable esx | ForEach-Object -Process { $esxcli = Get-EsxCli -VMHost $esx -V2 $esxcli.network.nic.list.Invoke() | ForEach-Object -Process { $esxcli.network.nic.stats.get.Invoke(@{nicname=$_.Name}) | Select @{N='Cluster';E={$cluster.Name}}, @{N='VMHost';E={$esxcli.VMHost.Name}}, NICName,PacketsReceived,PacketsSent,ReceiveCRCerrors } } | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture
    You cannot call a method on a null-valued expression.
    At line:1 char:120
    + ... -Process { $esxcli = Get-EsxCli -VMHost $esx -V2 $esxcli.network.nic ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    You cannot call a method on a null-valued expression.
    At line:1 char:120
    + ... -Process { $esxcli = Get-EsxCli -VMHost $esx -V2 $esxcli.network.nic ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull



  • 6.  RE: cmdlet to obtain CRC errors on hosts

    Posted Jul 07, 2022 06:17 PM

    Why did you change the PipelineVariable to 'xxx'?
    The rest of the code still references $esx



  • 7.  RE: cmdlet to obtain CRC errors on hosts

    Posted Jul 07, 2022 06:30 PM

    LucD

    PS C:\Users\xxx> Get-Cluster -PipelineVariable xxxx

    => in the above i just masked my clustername and folder path to dummy characters for privacy.

    other than that there are no changes in the cmd i have made

    so the cmd is being issued like this

     

    Get-Cluster -PipelineVariable myclustername | Get-VMHost -PipelineVariable esx | and goes on with the rest .. 



  • 8.  RE: cmdlet to obtain CRC errors on hosts

    Posted Jul 07, 2022 06:34 PM

    That will not work, the clustername should not be the argument for the PipelineVariable.

    Get-Cluster -Name <yourcluster>  -PipelineVariable cluster | 
    Get-VMHost -PipelineVariable esx | 

     



  • 9.  RE: cmdlet to obtain CRC errors on hosts

    Posted Jul 08, 2022 04:44 PM

    Hello LucD

    let us know your comments

    => This is what i am getting while running the cmdlet as it is, just connecting to vcenter and not adding anything to your original cmd

    PS C:\Users\txij\Downloads\Files> Get-Cluster -PipelineVariable cluster | Get-VMHost -PipelineVariable esx | ForEach-Object -Process { $esxcli = Get-EsxCli -VMHost $esx -V2 $esxcli.network.nic.list.Invoke() | ForEach-Object -Process { $esxcli.network.nic.stats.get.Invoke(@{nicname=$_.Name}) | Select @{N='Cluster';E={$cluster.Name}}, @{N='VMHost';E={$esxcli.VMHost.Name}}, NICName,PacketsReceived,PacketsSent,ReceiveCRCerrors } } | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture
    You cannot call a method on a null-valued expression.
    At line:1 char:102
    + ... -Process { $esxcli = Get-EsxCli -VMHost $esx -V2 $esxcli.network.nic ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    You cannot call a method on a null-valued expression.
    At line:1 char:102
    + ... -Process { $esxcli = Get-EsxCli -VMHost $esx -V2 $esxcli.network.nic ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    You cannot call a method on a null-valued expression.
    At line:1 char:102
    + ... -Process { $esxcli = Get-EsxCli -VMHost $esx -V2 $esxcli.network.nic ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    You cannot call a method on a null-valued expression.
    At line:1 char:102
    + ... -Process { $esxcli = Get-EsxCli -VMHost $esx -V2 $esxcli.network.nic ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException

     

     

    => this is what i am getting when i use your last tweak and enter the cluster name into the cmd

    PS C:\Users\txij\Downloads\Files> Get-Cluster -name XYZ -PipelineVariable cluster | Get-VMHost -PipelineVariable esx | ForEach-Object -Process { $esxcli = Get-EsxCli -VMHost $esx -V2 $esxcli.network.nic.list.Invoke() | ForEach-Object -Process { $esxcli.network.nic.stats.get.Invoke(@{nicname=$_.Name}) | Select @{N='Cluster';E={$cluster.Name}}, @{N='VMHost';E={$esxcli.VMHost.Name}}, NICName,PacketsReceived,PacketsSent,ReceiveCRCerrors } } | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture
    You cannot call a method on a null-valued expression.
    At line:1 char:134
    + ... -Process { $esxcli = Get-EsxCli -VMHost $esx -V2 $esxcli.network.nic ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    You cannot call a method on a null-valued expression.
    At line:1 char:134
    + ... -Process { $esxcli = Get-EsxCli -VMHost $esx -V2 $esxcli.network.nic ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    You cannot call a method on a null-valued expression.
    At line:1 char:134
    + ... -Process { $esxcli = Get-EsxCli -VMHost $esx -V2 $esxcli.network.nic ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    You cannot call a method on a null-valued expression.
    At line:1 char:134
    + ... -Process { $esxcli = Get-EsxCli -VMHost $esx -V2 $esxcli.network.nic ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull



  • 10.  RE: cmdlet to obtain CRC errors on hosts

    Posted Jul 08, 2022 04:52 PM

    You are ignoring the LF in my original code.
    This for example are 2 lines

      $esxcli = Get-EsxCli -VMHost $esx -V2
      $esxcli.network.nic.list.Invoke() |

    Are you just copy/paste my code at the prompt?
    You are definitely loosing the LF and CR.

    Place the code in a .ps1 file, and run that .ps1 file



  • 11.  RE: cmdlet to obtain CRC errors on hosts

    Posted Jul 09, 2022 01:41 AM

    yep that works, thanks a lot