PowerCLI

 View Only
Expand all | Collapse all

PowerCLI on Debian Stretch: The type initializer for 'VMware.VimAutomation.ViCore.Util10.SettingsManager' threw an exception.

  • 1.  PowerCLI on Debian Stretch: The type initializer for 'VMware.VimAutomation.ViCore.Util10.SettingsManager' threw an exception.

    Posted Aug 10, 2018 09:17 AM

    Environment

    OS: Debian 9 Stretch amd64

    PS /root> get-host
    Name             : ConsoleHost
    Version          : 6.1.0-preview.2
    InstanceId       : 87acc50e-d2c7-4bf8-a667-5ddb22848a61
    UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
    CurrentCulture   : de-DE
    CurrentUICulture : de-DE
    PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
    DebuggerEnabled  : True
    IsRunspacePushed : False
    Runspace         : System.Management.Automation.Runspaces.LocalRunspace

    Import-Module VMware.VimAutomation.Core
    Get-Module VMware* | Select Name,Version

    PS /root> Get-Module VMware* | Select Name,Version

    Name                          Version
    ----                          -------
    VMware.Vim                    6.7.0.8343295
    VMware.VimAutomation.Cis.Core 10.1.0.8377811
    VMware.VimAutomation.Common   10.1.0.8342134
    VMware.VimAutomation.Core     10.1.0.8344055
    VMware.VimAutomation.Sdk      10.1.0.8342078

    Description

    Due to the new possibilites Microsoft offers the Linux community, I installed Microsoft PowerShell and Vmware PowerCLI on Debian.
    I want Zabbix Proxy to query VMware vCenter via External check.

    I wrote the following script:

    #!/usr/bin/pwsh
     
    param(
    [string]$Server,
    [string]$User,
    [string]$Password,
    [string]$VM
    )
    Import-Module VMware.VimAutomation.Core
    Connect-VIServer -Server $Server -User $User -Password $Password -Force | Out-Null
     
    $snapshot = Get-Snapshot -VM $VM
    $snapshot.Count
     
    Disconnect-VIServer -Server * -Force -Confirm:$false

     

    The script works very vell, when I start it in my SSH session. But as soon as Zabbix executes the script, the Module fails:

    VERBOSE: Import-Module:
    Import-Module : The type initializer for 'VMware.VimAutomation.ViCore.Util10.SettingsManager' threw an exception.
    At /usr/lib/zabbix/externalscripts/vmware.vm.snapshot.count.ps1:22 char:1
    + Import-Module VMware.VimAutomation.Core
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : OperationStopped: (:) [Import-Module], TypeInitializationException
    + FullyQualifiedErrorId : System.TypeInitializationException,Microsoft.PowerShell.Commands.ImportModuleCommand

    Is this a bug I can report anywhere? Is this egiable for Vmware support? Or can someone help me here?



  • 2.  RE: PowerCLI on Debian Stretch: The type initializer for 'VMware.VimAutomation.ViCore.Util10.SettingsManager' threw an exception.

    Posted Aug 10, 2018 10:04 AM

    There are a couple of things to note (see Release Notes):

    • Debian is currently not in the list of officially supported OS
    • PowerCLI is officially only supported with PowerShell 6.0.2, afaik due to a breaking change in the NetCore libraries

    Would you eventually have the option to go back to PowerShell Core 6.0.2?

    Since the script seems to work when you run it under your credentials, is Zabbix running under the same account?
    Do you have the same Path definitions for both accounts?

    On your support question, see PowerCLI Support Breakdown

    But since you are using an OS and a PS version that is not officially supported, I'm doubtful that you would be able to open a SR.

    But the community (where you asked) might help.



  • 3.  RE: PowerCLI on Debian Stretch: The type initializer for 'VMware.VimAutomation.ViCore.Util10.SettingsManager' threw an exception.

    Posted Aug 10, 2018 02:12 PM

    In the last hour I installed a completely new additional Zabbix Proxy. It's Ubuntu 16.04. I Installed PowerShell Core 6.0.2.

    root@zabbix-ubuntu:/usr/lib/zabbix/externalscripts# lsb_release -a
    No LSB modules are available.
    Distributor ID: Ubuntu
    Description:    Ubuntu 16.04.5 LTS
    Release:        16.04
    Codename:       xenial

    get-host

    Name             : ConsoleHost
    Version          : 6.0.2
    InstanceId       : db63dd07-ea01-4e6e-9a6d-213bfdc66dd5
    UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
    CurrentCulture   : de-DE
    CurrentUICulture : de-DE
    PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
    DebuggerEnabled  : True
    IsRunspacePushed : False
    Runspace         : System.Management.Automation.Runspaces.LocalRunspace

    PS /usr/lib/zabbix/externalscripts> Import-Module VMware.VimAutomation.Core
    PS /usr/lib/zabbix/externalscripts> Get-Module VMware* | Select Name,Version                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      Name                          Version
    ----                          -------
    VMware.Vim                    6.7.0.8343295
    VMware.VimAutomation.Cis.Core 10.1.0.8377811
    VMware.VimAutomation.Common   10.1.0.8342134
    VMware.VimAutomation.Core     10.1.0.8344055
    VMware.VimAutomation.Sdk      10.1.0.8342078

    Debian is currently not in the list of officially supported OS
    > I switched to Ubuntu, the error persists.

    > Would you eventually have the option to go back to PowerShell Core 6.0.2?
    I switched to PowerShell 6.0.2, the error persists.

    > Since the script seems to work when you run it under your credentials, is Zabbix running under the same account?
    Yes, I checked running the script as the deamon user. No difference.

    > Do you have the same Path definitions for both accounts?
    Yes.

    How can we furher test? I attach the log:

    Value "Script Name
    vmware.vm.snapshot.count.ps1
    VCSA Host IP
    10.23.0.200
    Username
    monitoring@vsphere.local
    Password
    xxx
    Virtual machine
    server-domain.local
    VERBOSE: Server:
    10.23.0.200
    VERBOSE: User:
    monitoring@vsphere.local
    VERBOSE: Password:
    xxx
    VERBOSE: VM:
    server-domain.local
    VERBOSE: Connection string:
    Connect-VIServer -Server 10.23.0.200 -User monitoring@vsphere.local -Password xxx -Force


    Name : ConsoleHost
    Version : 6.0.2
    InstanceId : 5d257a8c-98d3-4787-b4a3-a02cd71c7141
    UI : System.Management.Automation.Internal.Host.InternalHostUserI
    nterface
    CurrentCulture : de-DE
    CurrentUICulture : de-DE
    PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
    DebuggerEnabled : True
    IsRunspacePushed : False
    Runspace : System.Management.Automation.Runspaces.LocalRunspace

    VERBOSE: Import-Module:
    Import-Module : The type initializer for 'VMware.VimAutomation.ViCore.Util10.SettingsManager' threw an exception.
    At /usr/lib/zabbix/externalscripts/vmware.vm.snapshot.count.ps1:25 char:1
    + Import-Module VMware.VimAutomation.Core
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : OperationStopped: (:) [Import-Module], TypeInitializationException
    + FullyQualifiedErrorId : System.TypeInitializationException,Microsoft.PowerShell.Commands.ImportModuleCommand

    VERBOSE: Get-Module:
    Name : VMware.VimAutomation.Sdk
    Version : 10.1.0.8342078

    Connect-VIServer : The type initializer for 'VMware.VimAutomation.ViCore.Util10.SettingsManager' threw an exception.
    At /usr/lib/zabbix/externalscripts/vmware.vm.snapshot.count.ps1:30 char:1
    + Connect-VIServer -Server $Server -User $User -Password $Password -For ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Connect-VIServer], TypeInitializationException
    + FullyQualifiedErrorId : System.TypeInitializationException,VMware.VimAutomation.ViCore.Cmdlets.Commands.Co



  • 4.  RE: PowerCLI on Debian Stretch: The type initializer for 'VMware.VimAutomation.ViCore.Util10.SettingsManager' threw an exception.

    Posted Aug 10, 2018 02:57 PM

    Can you find out which netcore version you are running?



  • 5.  RE: PowerCLI on Debian Stretch: The type initializer for 'VMware.VimAutomation.ViCore.Util10.SettingsManager' threw an exception.

    Posted Aug 14, 2018 12:59 PM

    I don't think I have an answer. If I do "apt search netcore" I do find several releases, but none of them are installed.

    What I did to install PowerShell is:

    curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -

    curl -o /etc/apt/sources.list.d/microsoft.list https://packages.microsoft.com/config/ubuntu/16.04/prod.list

    apt update

    apt install powershell=6.0.2-1.ubuntu.16.04

    pwsh

    Install-Module -Name VMware.PowerCLI -Force



  • 6.  RE: PowerCLI on Debian Stretch: The type initializer for 'VMware.VimAutomation.ViCore.Util10.SettingsManager' threw an exception.

    Posted Sep 11, 2018 12:32 PM

    Any chance we could continue working on this? Any other playe I could get official support?



  • 7.  RE: PowerCLI on Debian Stretch: The type initializer for 'VMware.VimAutomation.ViCore.Util10.SettingsManager' threw an exception.

    Posted Sep 11, 2018 12:46 PM

    If you have installed all the components as listed in the latest VMware PowerCLI 10.2.0 Release Notes​​, you should be able to open a SR.


    When opening a SR the GSS people might try to tell you that there is no support for PowerCLI unless you have a Developer Support Contract.

    In that case refer to PowerCLI Support Breakdown



  • 8.  RE: PowerCLI on Debian Stretch: The type initializer for 'VMware.VimAutomation.ViCore.Util10.SettingsManager' threw an exception.
    Best Answer

    Posted Sep 20, 2018 08:56 AM

    Hello,

    I have tried a similar action and had the same error.

    RootCause: The service account does not have a "HOME" environment variable set

    Solution: Create an environment variable HOME set to /tmp/ for example and it works.

    What led me to investigate environment variable was the error:

    Parameter name: path1: ArgumentNullException

      at System.IO.Path.Combine(String path1, String path2)

      at VMware.VimAutomation.ViCore.Util10.SettingsManager.GetUserSettingsLocation(Nullable`1 targetPlatform)

      at VMware.VimAutomation.ViCore.Util10.SettingsManager..cctor()

    Regards,

    Joseph



  • 9.  RE: PowerCLI on Debian Stretch: The type initializer for 'VMware.VimAutomation.ViCore.Util10.SettingsManager' threw an exception.

    Posted Sep 20, 2018 08:58 AM

    Thanks, great find!



  • 10.  RE: PowerCLI on Debian Stretch: The type initializer for 'VMware.VimAutomation.ViCore.Util10.SettingsManager' threw an exception.

    Posted Sep 20, 2018 01:35 PM

    You are my hero! I spent so much time to built this function for Zabbix! I never would have checked Environment Variables!

    I simply but "env" at the beginning of all my scripts to check, what is written there, compared to all my manual tests. And tada, instead of ~12 variables it were only ~5. HOME was missing.

    Then I removed all debug code and tests etc, and used the original script I wrote, but added "export HOME=/var/lib/zabbix/" in the second line of the script. A few minutes later it started working! This is brilliant!

    We now have to ability, to execute PowerShell scripts from our Debian Linux Zabbix Proxy, against Windows or VMware Hosts for example, and the results get reported to the Zabbix Server. This offers so many new possibilities!

    Thank you again!



  • 11.  RE: PowerCLI on Debian Stretch: The type initializer for 'VMware.VimAutomation.ViCore.Util10.SettingsManager' threw an exception.

    Posted May 22, 2024 05:15 AM

    Thank you so much! I was struggling with this issue for weeks off and on, could not find any info about it anywhere - but this makes perfect sense! Without having $HOME set, it does not have a place to save user settings. Excellent find!