Invoke-VMScript Object reference not set to an instance of an object.from VMware.VimAutomation.ViCore.Impl.V1.VixHelper.GetVixVersion()

StackOverflow https://stackoverflow.com/questions/21148568

Question

Invoke-VMScript
Object reference not set to an instance of an object.

Which ultimately has come from :
VMware.VimAutomation.ViCore.Impl.V1.VixHelper.GetVixVersion()

On my machine, Invoke-VMScript fails when pointing at a VMGuest whose operating system is a flavor of Linux.
* Another developer is able to run this script without problems.
* He and I have matched PowerCLI and Vix versions.
* It is not an authentication problem
** I can go to his machine, use my windows credentials and the script runs
** He can come to my machine, use his windows credentials and the script throws

C:\run_a_bash_script.ps1 :

$my_fullname_vmIpChangeLin_ps1        = ( $MyInvocation.MyCommand.Definition )
$my_dir_vmIpChangeLin_ps1            = ( Split-Path $my_fullname_vmIpChangeLin_ps1 )

import-module "$( $my_dir_vmIpChangeLin_ps1 )\libs\ooooops\ooooops.psm1" -force

Set-StrictMode -Version:Latest
$GLOBAL:ErrorActionPreference               = "Stop"

Add-PSSnapin VMware.VimAutomation.Core
. "$( $my_dir_vmIpChangeLin_ps1 )\libs\Initialize-PowerCLIEnvironment.ps1" 


 [string]$repoServer        = <# VCenter FQDN #>
 [string]$repoUser          = <# AD username #>
 [string]$repoPassword      = <# password #>
 [string]$vmName            = <# vm logical name #>
 [string]$vmUser            = <# username on linux machine #>
 [string]$vmPassword        = <# password #>


# set to match the working powercli configuration
$null = ( Set-PowerCLIConfiguration -DefaultVIServerMode:Multiple -ProxyPolicy:UseSystemProxy -DisplayDeprecationWarnings:$true -InvalidCertificateAction:Ignore -Confirm:$false )
Connect-VIServer -Server $repoServer -User $repoUser -Password $repoPassword -WarningAction:SilentlyContinue
$script = "ls"


try
{
    Invoke-VMScript -VM $vmName -ScriptText $script -GuestUser $vmUser -GuestPassword $vmPassword -Confirm:$false | Select -ExpandProperty ScriptOutput
}
catch
{
    $desc = (ooooops_describe_error -obj:$_)
    write-host $desc
}

Running the script :

PS c:\> C:\run_a_bash_script.ps1

Script Results :

Name                           Port  User                          
----                           ----  ----                          
<# VCenter FQDN #>             443   <# AD username #>                  

========ERROR SUMMARY=========================================================================================

1/14/2014 4:30:22 PM    Invoke-VMScript     Object reference not set to an instance of an object.   
Object reference not set to an instance of an object.

NotSpecified: (:) [Invoke-VMScript], ViError

at <ScriptBlock>, C:\projects\github\nodeVM\scripts\powershell\vmIpChangeLin.ps1: line 20
VALUE_IS_NULL
   at VMware.VimAutomation.ViCore.Impl.V1.VixHelper.GetVixVersion()
   at VMware.VimAutomation.ViCore.Impl.V1.VixHelper.TryValidateVixVersion()
   at VMware.VimAutomation.ViCore.Impl.V1.Service.VmGuestServiceImpl.<>c__DisplayClassc.<RunScriptInGuest>b__b(ClientSideTask , Object )
   at VMware.VimAutomation.Sdk.Util10.Task.ClientSideTaskImpl.ThreadProc(Object obj)
At C:\projects\github\nodeVM\scripts\powershell\vmIpChangeLin.ps1:20 char:5
+     Invoke-VMScript -VM $vmName -ScriptText $script -GuestUser $vmUser -GuestPas ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
==============================================================================================================


     BEGIN---> describe_error_briefly

          BEGIN---> exception
               exception                            =[NULL]
          END---> exception


          BEGIN---> run_time_exception
               is a runtime exception?              =[NO]
          END---> run_time_exception


          BEGIN---> error_record
               CategoryInfo                         =[NotSpecified: (:) [Invoke-VMScript], ViError]
               ErrorDetails                         =[VALUE_IS_NULL]
               FullyQualifiedErrorId                =[Client20_ClientSideTaskImpl_ThreadProc_UnhandledException,VMware.VimAutomation.ViCore.Cmdlets.Commands.InvokeVmScript]
               ScriptStackTrace                     =[at <ScriptBlock>, C:\projects\github\nodeVM\scripts\powershell\vmIpChangeLin.ps1: line 20]
               TargetObject                         =[VALUE_IS_NULL]

               BEGIN---> exception
                    Data                                 =[System.Collections.ListDictionaryInternal]
                    Message                              =[1/14/2014 4:30:22 PM Invoke-VMScript     Object reference not set to an instance of an object.   ]
                    Source                               =[VALUE_IS_NULL]
                    StackTrace                           =[VALUE_IS_NULL]
                    TargetSite                           =[VALUE_IS_NULL]

                    BEGIN---> exception
                         Data                                 =[System.Collections.ListDictionaryInternal]
                         Message                              =[Object reference not set to an instance of an object.]
                         Source                               =[VMware.VimAutomation.ViCore.Impl]
                         StackTrace                           =[   at VMware.VimAutomation.ViCore.Impl.V1.VixHelper.GetVixVersion()
                                                               |   at VMware.VimAutomation.ViCore.Impl.V1.VixHelper.TryValidateVixVersion()
                                                               |   at VMware.VimAutomation.ViCore.Impl.V1.Service.VmGuestServiceImpl.<>c__DisplayClassc.<RunScriptInGuest>b__b(ClientSideTask , Object )
                                                               |   at VMware.VimAutomation.Sdk.Util10.Task.ClientSideTaskImpl.ThreadProc(Object obj)]
                         TargetSite                           =[System.String GetVixVersion()]

                         BEGIN---> exception
                              exception                            =[NULL]
                         END---> exception

                    END---> exception

               END---> exception


               BEGIN---> invocation_info
                    PositionMessage                      =[At C:\projects\github\nodeVM\scripts\powershell\vmIpChangeLin.ps1:20 char:5
                                                          |+     Invoke-VMScript -VM $vmName -ScriptText $script -GuestUser $vmUser -GuestPas ...
                                                          |+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~]
               END---> invocation_info

          END---> error_record

     END---> describe_error_briefly

The method does not seem to exist

both of these return $null

write-host ( [VMware.VimAutomation.ViCore.Impl.V1.VixHelper] | Get-Member -MemberType:All | Where-Object { $_.Name -like "%ersion%" } | Format-Table | Out-String )

and

write-host ( [VMware.VimAutomation.ViCore.Impl.V1.VixHelper] | Get-Member -MemberType:All -Static | Where-Object { $_.Name -like "%ersion%" } | Format-Table | Out-String )

Windows Os, ControlPanel / Programs / Programs and Features

  • VMWare VIX 1.12.1.33347
  • VMWare vSphere PowerCLI 5.5.0.5836

PowerCLI Versions / Configuration

Function get_debug_info()
{
    write-host "-----------Get-PowerCLIConfiguration--------------------------------------------------"
    write-host ( Get-PowerCLIConfiguration | Format-List | Out-String )
    write-host "-----------Get-PowerCLIVersion--------------------------------------------------"
    write-host ( Get-PowerCLIVersion | Format-List | Out-String )
    return $null
}

For the one that works

-----------Get-PowerCLIConfiguration-------------------------------------------------- 


DefaultVIServerMode : Multiple 
ProxyPolicy : UseSystemProxy 
DisplayDeprecationWarnings : True 
InvalidCertificateAction : Ignore 
WebOperationTimeoutSeconds : 300 
VMConsoleWindowBrowser : 
Scope : Session 

DefaultVIServerMode : Multiple 
ProxyPolicy : 
DisplayDeprecationWarnings : 
InvalidCertificateAction : 
WebOperationTimeoutSeconds : 
VMConsoleWindowBrowser : 
Scope : User 

DefaultVIServerMode : Single 
ProxyPolicy : 
DisplayDeprecationWarnings : True 
InvalidCertificateAction : Ignore 
WebOperationTimeoutSeconds : 
VMConsoleWindowBrowser : 
Scope : AllUsers 




-----------Get-PowerCLIVersion-------------------------------------------------- 


Major : 5 
Minor : 5 
Build : 1295336 
Revision : 0 
Copyright : Copyright © VMware, Inc. 1998-2013 
Company : VMware, Inc. 
UserFriendlyVersion : VMware vSphere PowerCLI 5.5 Release 1 build 1295336 
SnapinVersions : {VMWare AutoDeploy PowerCLI Component 5.5 build 1262826, VMWare ImageBuilder PowerCLI Component 5.5 build 1262826, VMware License PowerCLI Component 5.5 build 1265954, VMware VDS PowerCLI Component 5.5 build 1295334...} 

For the one that does not work

-----------Get-PowerCLIConfiguration--------------------------------------------------


DefaultVIServerMode        : Single
ProxyPolicy                : UseSystemProxy
DisplayDeprecationWarnings : True
InvalidCertificateAction   : Ignore
WebOperationTimeoutSeconds : 300
VMConsoleWindowBrowser     : 
Scope                      : Session

DefaultVIServerMode        : Single
ProxyPolicy                : 
DisplayDeprecationWarnings : 
InvalidCertificateAction   : 
WebOperationTimeoutSeconds : 
VMConsoleWindowBrowser     : 
Scope                      : User

DefaultVIServerMode        : Multiple
ProxyPolicy                : UseSystemProxy
DisplayDeprecationWarnings : True
InvalidCertificateAction   : Ignore
WebOperationTimeoutSeconds : 
VMConsoleWindowBrowser     : 
Scope                      : AllUsers




-----------Get-PowerCLIVersion--------------------------------------------------


Major               : 5
Minor               : 5
Build               : 1295336
Revision            : 0
Copyright           : Copyright © VMware, Inc. 1998-2013
Company             : VMware, Inc.
UserFriendlyVersion : VMware vSphere PowerCLI 5.5 Release 1 build 1295336
SnapinVersions      : {VMWare AutoDeploy PowerCLI Component 5.5 build 1262826, VMWare ImageBuilder PowerCLI Component 5.5 build 1262826, VMware License PowerCLI Component 5.5 build 1265954, VMware VDS PowerCLI Component 5.5 build 1295334...}
Was it helpful?

Solution 2

As described here:
* http://www.virten.net/2013/06/run-scripts-in-linux-guests-by-using-vmware-tools/
* http://www.lucd.info/2012/01/01/will-invoke-vmscript-work/
* https://communities.vmware.com/message/2314207

The problem is that the VIX libraries are 32 bit and I was running the script using 64 bit Powershell.

On a 64 bit OS :
* Powershell 64 bit is the default
* the path to the 32 bit Powershell is : %systemroot%\syswow64\windowspowershell\v1.0\

A simple powershell statement to test if the powershell process is 32 or 64 bit:

 [Environment]::Is64BitProcess

OTHER TIPS

I had faced the same problem. My Invoke-VMScript was not working. After digging deep into it I found my vCenter server(in my case the target server) was having ipv6 configuration. I removed the ipv6 configuration and changed it to ipv4 configuration.

My issue got resolved.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top