簡體   English   中英

從VMware.VimAutomation.ViCore.Impl.V1.VixHelper.GetVixVersion(),未將Invoke-VMScript對象引用設置為對象的實例。

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

調用-VMScript
你調用的對象是空的。

最終來自:
VMware.VimAutomation.ViCore.Impl.V1.VixHelper.GetVixVersion()

在我的機器上,當指向操作系統為Linux的VMGuest時,Invoke-VMScript失敗。
*另一個開發人員可以運行此腳本而不會出現問題。
*他和我匹配了PowerCLI和Vix版本。
*不是身份驗證問題
**我可以轉到他的機器上,使用我的Windows憑據運行腳本
**他可以來我的機器,使用Windows憑據和腳本拋出

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
}

運行腳本:

PS c:\> C:\run_a_bash_script.ps1

腳本結果:

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

該方法似乎不存在

這兩個都返回$ null

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

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

Windows操作系統,ControlPanel /程序/程序和功能

  • VMWare VIX 1.12.1.33347
  • VMWare vSphere PowerCLI 5.5.0.5836

PowerCLI版本/配置

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
}

對於一個有效的

-----------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...} 

對於那不起作用的

-----------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...}

我曾經遇到過同樣的問題。 我的Invoke-VMScript無法正常工作。 深入研究后,我發現我的vCenter Server(以我的情況為目標服務器)具有ipv6配置。 我刪除了ipv6配置,並將其更改為ipv4配置。

我的問題解決了。

如此處所述:
* 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

問題是VIX庫是32位的,而我正在使用64位Powershell運行腳本。

在64位操作系統上:
* Powershell 64位是默認值
* 32位Powershell的路徑是:%systemroot%\\ syswow64 \\ windowspowershell \\ v1.0 \\

一個簡單的powershell語句,用於測試powershell進程是32位還是64位:

 [Environment]::Is64BitProcess

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM