Automation

 View Only
  • 1.  Error when runing PowerCLI from .Net application

    Posted Oct 27, 2020 10:37 AM

    Hi,

    I have a .Net app which runs some PowerCLI scripts. I've recently had to rebuild my PC an LAB environment and now certain comands are throwing an error.

    The error is : "Could not retrieve handler field info from the HttpClient .net type."

    It only seems to happen with cetain cmdlets such as:

    Start-VM

    Stop-VM

    Set-VM

    New-VM

    Which are the cmdlets which conflict with the Hyper-V module. I haven't installed the Hyper-V module and doing a (get-module -ListAvailable).path doesn't tell me its installed.

    I'm using the latest version of PowerCLI , but have also tried installing older versions

    My $psversiontable is:

    Name                           Value

    ----                           -----

    PSVersion                      5.1.18362.1110

    PSEdition                      Desktop

    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}

    BuildVersion                   10.0.18362.1110

    CLRVersion                     4.0.30319.42000

    WSManStackVersion              3.0

    PSRemotingProtocolVersion      2.3

    SerializationVersion           1.1.0.1

    Versions of .Net installed

    >=4.x        : 4.8 or later

    v4\Client    : Installed

    v4\Full      : Installed

    v3.5         : Installed

    v3.0         : Installed

    v2.0.50727   : Installed

    v1.1.4322    : Not installed (no key)

    I'm using vSphere 6.7

    This only happens when running the scripts from my .Net app and was all working fine before I had to recreate my environment.

    If i run the scripts from within PowerShell they run with no issue, which I know points to somekind of conflict with my app and not a PowerCli issus but im a bit lost as to know where to go next , so hoping someone can shed some light. Searching for the error online doesn't throw up anything.

    thanks in advance



  • 2.  RE: Error when runing PowerCLI from .Net application

    Posted Oct 27, 2020 10:42 AM

    Did you check your .NET app build that it doesn't include any Hyper-V related DLLs?



  • 3.  RE: Error when runing PowerCLI from .Net application

    Posted Oct 27, 2020 08:13 PM

    Yes i've checked that.

    One thing i didn't mention is the commands do actual work, however they throw the error after completing..



  • 4.  RE: Error when runing PowerCLI from .Net application

    Posted Oct 27, 2020 08:30 PM

    I would guess that logging and tracing the app might shed some light on what happens.

    But I'm afraid that I'm not a .NET developer who can help you with setting that up :smileysad:



  • 5.  RE: Error when runing PowerCLI from .Net application

    Posted Oct 27, 2020 09:06 PM

    No problem thanks.

    one thing you might be able to help with..

    I'm working on a work around for the time being. I can get around the issue with start-vm, stop-vm etc by filteirng the error.

    However, when using New-VM with the following code

    $vmDeployTask = New-VM -Template $vmWareTemplate -VMHost $vmHost -Name $vmName -Datastore $vmwareDatastore -OSCustomizationSpec $osCustSpec -RunAsync

    i can't track the deployment because $vmDeployTask just contains the error.

    Is there a way to use Get-Task and search for the name of the deployed target VM name? So something like.. (Where "NewVM" is the name of the deployed VM)

    Get-Task | ?{$_.description -contains "NewVM"}

    I've tried looking the properties of a CloneVM_task but can't find anything which containts the name of the new VM?



  • 6.  RE: Error when runing PowerCLI from .Net application

    Posted Oct 27, 2020 09:41 PM

    One way is to use the Get-VIEvent cmdlet and look for the VMBeingClonedEvent and the VMClonedEvent.

    That would allow you to determine when the clone is completed.

    Another option is to look, again with Get-VIEvent, for a TaskEvent.
    Under the Info property of that event, you will find information about the progress and the result of the Task.