调用-VMScript
对象引用未设置为对象的实例。
最终来自:
VMware.VimAutomation.ViCore.Impl.V1.VixHelper.GetVixVersion()
在我的机器上,当指向操作系统是Linux风格的VMGuest时,Invoke-VMScript失败。
*另一位开发人员可以毫无问题地运行此脚本
*他和我匹配PowerCLI和Vix版本
*这不是身份验证问题
**我可以去他的机器,使用我的Windows凭据,脚本运行
**他可以来我的机器,使用他的Windows凭据和脚本抛出
$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 )
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...}
答案 0 :(得分:1)
我遇到了同样的问题。我的Invoke-VMScript无效。在深入研究之后,我发现我的vCenter服务器(在我的情况下是目标服务器)正在进行ipv6配置。我删除了ipv6配置并将其更改为ipv4配置。
我的问题得到了解决。
答案 1 :(得分:0)
如下所述:
* 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