VMware Cloud Community
housamsmadi
Contributor
Contributor

Object reference not set to an instance of an object Server 2016

Hi guys,

I'm running into an issue related to the VMware.PowerCLI module.

When I try to run the invoke-VMscript using PowerShell on windows server 2016 i get the following reply:

Invoke-VMScript : 3/5/2018 11:11:43 AM Invoke-VMScript  Object reference not set to an instance of an object. At line:37 char:17+ ... iptresult = Invoke-VMScript -VM TestVM -ScriptText $command -GuestU ...+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : NotSpecified: (:) [Invoke-VMScript], ViError    + FullyQualifiedErrorId : Client20_VmGuestServiceImpl_DownloadFileFromGuest_DownloadError,VMware.Vim     Automation.ViCore.Cmdlets.Commands.InvokeVmScript

While it works perfectly when I run the same command using PowerShell on Windows 10. 

 

According to VMware, this module is compitable with Windows Server 2016 and Windows 10 as well:

https://vdc-download.vmware.com/vmwb-repository/dcr-public/6a356389-4ad9-4f87-84f3-184881d48fe8/deea...

Here is the script:

$vcserver = "vcenterserver.example.com"  $vmuser = "myvcenteruser"  $vmpassword = 'vcenterpassword'$vmprotocol = "HTTPS"  #connect to VirtualCenter with credentialsget-viserver -server $vcserver -user $vmuser -password $vmpassword -Protocol $vmprotocol   $command = "ifconfig"$guestuser = "rootuser"$guestpassword = 'rootpassword'$scriptresult = Invoke-VMScript -VM TestVM -ScriptText $command -GuestUser $guestuser -GuestPassword $guestpassword -ScriptType Bash  $scriptresult.ScriptOutput
 

Does anyone have the same issue?

 

Thanks in Advanced

Housam 

0 Kudos
13 Replies
LucD
Leadership
Leadership

That should be Connect-VIServer not Get-VIServer

$vcserver = "vcenterserver.example.com" 

$vmuser = "myvcenteruser" 

$vmpassword = 'vcenterpassword'

$vmprotocol = "HTTPS" 

#connect to VirtualCenter with credentials

Connect-VIServer -server $vcserver -user $vmuser -password $vmpassword -Protocol $vmprotocol  

$command = "ifconfig"

$guestuser = "rootuser"

$guestpassword = 'rootpassword'

$scriptresult = Invoke-VMScript -VM TestVM -ScriptText $command -GuestUser $guestuser -GuestPassword $guestpassword -ScriptType Bash

$scriptresult.ScriptOutput


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
housamsmadi
Contributor
Contributor

Thanks for your reply, but I got the same error message.

I don't know why it works on Windows 10 not Windows Server 2016.

0 Kudos
LucD
Leadership
Leadership

Let's compare the two environments.

Is the PowerSHell version the same, display  $PSVersionTable.

Then check if the sam ePowerCLI is installed. Do a

Get-Module -Name VMware* -ListAvailable | Select Name,Version


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
housamsmadi
Contributor
Contributor

Well, Windows 10 has the earlier version of PowerCLI installed, but even when I tried to unistall and reinstall the same version on Windows Server 2016, I ran into the same problem.

WIndows Server 2016:
 

PS C:\Users\Administrator> $PSVersionTable
Name                           Value                                                                                                                                                          
----                           -----                                                                                                                                                          
PSVersion                      5.1.14393.2068                                                                                                                                                 
PSEdition                      Desktop                                                                                                                                                        
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                        
BuildVersion                   10.0.14393.2068                                                                                                                                                
CLRVersion                     4.0.30319.42000                                                                                                                                                
WSManStackVersion              3.0                                                                                                                                                            
PSRemotingProtocolVersion      2.3                                                                                                                                                            
SerializationVersion           1.1.0.1  
 
PS C:\Users\Administrator> Get-Module -Name VMware* -ListAvailable | Select Name,Version
Name                                Version      
----                                -------      
VMware.DeployAutomation             6.5.2.7812840
VMware.ImageBuilder                 6.5.2.7812840
VMware.PowerCLI                     10.0.0.7895300
VMware.VimAutomation.Cis.Core       10.0.0.7893915
VMware.VimAutomation.Cloud          10.0.0.7893901
VMware.VimAutomation.Common         10.0.0.7893906
VMware.VimAutomation.Core           10.0.0.7893909
VMware.VimAutomation.HA             6.5.4.7567193
VMware.VimAutomation.HorizonView    7.1.0.7547311
VMware.VimAutomation.License        10.0.0.7893904
VMware.VimAutomation.Nsxt           10.0.0.7893913
VMware.VimAutomation.PCloud         10.0.0.7893924
VMware.VimAutomation.Sdk            10.0.0.7893910
VMware.VimAutomation.Srm            10.0.0.7893900
VMware.VimAutomation.Storage        10.0.0.7894167
VMware.VimAutomation.StorageUtility 1.2.0.0      
VMware.VimAutomation.Vds            10.0.0.7893903
VMware.VimAutomation.Vmc            10.0.0.7893902
VMware.VimAutomation.vROps          10.0.0.7893921
VMware.VumAutomation                6.5.1.7862888
 
 
 
Windows 10:
 
PS C:\Users\housam> $PSVersionTable
Name                           Value                                                                                                                                                         
----                           -----                                                                                                                                                         
PSVersion                      5.1.16299.248                                                                                                                                                 
PSEdition                      Desktop                                                                                                                                                       
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                       
BuildVersion                   10.0.16299.248                                                                                                                                                
CLRVersion                     4.0.30319.42000                                                                                                                                               
WSManStackVersion              3.0                                                                                                                                                           
PSRemotingProtocolVersion      2.3                                                                                                                                                           
SerializationVersion           1.1.0.1   
 
 
PS C:\Users\housam> Get-Module -Name VMware* -ListAvailable | Select Name,Version
Name                                Version     
----                                -------     
VMware.DeployAutomation             6.5.1.6997673
VMware.ImageBuilder                 6.5.1.6997673
VMware.PowerCLI                     6.5.4.7155375
VMware.VimAutomation.Cis.Core       6.5.4.6983166
VMware.VimAutomation.Cloud          6.5.1.5375799
VMware.VimAutomation.Common         6.5.4.6979861
VMware.VimAutomation.Core           6.5.2.6234650
VMware.VimAutomation.HA             6.5.4.7147627
VMware.VimAutomation.HorizonView    7.1.0.5307191
VMware.VimAutomation.License        6.5.1.5375648
VMware.VimAutomation.Nsxt           2.0.0.6870461
VMware.VimAutomation.PCloud         6.5.1.5376282
VMware.VimAutomation.Sdk            1.0.0.5334677
VMware.VimAutomation.Srm            6.5.1.5374694
VMware.VimAutomation.Storage        6.5.4.7154886
VMware.VimAutomation.StorageUtility 1.1         
VMware.VimAutomation.Vds            6.5.1.5374428
VMware.VimAutomation.Vmc            6.5.4.7086404
VMware.VimAutomation.vROps          6.5.1.5375723
VMware.VumAutomation                6.5.1.5301639
 
 
 
 
0 Kudos
LucD
Leadership
Leadership

Ok, it would be interesting to compare the vmware.log content for both systems.

Since the Invoke-VMScript uses the VMware Tools API to communicate with the guest OS, we should see some entries in those logs for what is actually happening.

My first impression, from the error message, is that the script doesn't even get to the guest OS, but I would like to verify that with the content of the vmware.logs.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
LucD
Leadership
Leadership

Hold on, I just noticed there is in fact a "DownloadError" in the message.

Did you try on platforms with the Firewall disabled?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
housamsmadi
Contributor
Contributor

I've just tried to run other script to make sure that it's working, like changing IP address:

$command = "sed -i -e 's/185.69.232.28/185.69.232.46/g' /etc/sysconfig/network-scripts/ifcfg-eth01 && service network restart"

and this has been invoked, so the issue seems that I'm not getting the response back from the VM. (Firewall is disabled)

0 Kudos
LucD
Leadership
Leadership

To make sure I get that correctly, the script is invoked inside the guest OS with success?

But the output is not returned?

I would still like you to check if there is anything in the VM's vmware.log around the time the Invoke-VMScript was executed.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
housamsmadi
Contributor
Contributor

Yes, the script invoked inside the guest OS with success but the output isn't returned, here is the log from both tries:

This is the log that has been generated when  the output is NOT returned

Guest operation Delete File performed.                                    Information 3/5/2018 4:28:37 PM 

Guest operation Initiate File Transfer From Guest performed. Information 3/5/2018 4:28:37 PM 

Guest operation Initiate File Transfer From Guest performed. Information 3/5/2018 4:28:37 PM 

Guest operation Initiate File Transfer From Guest performed. Information 3/5/2018 4:28:37 PM 

Guest operation List Processes performed.                             Information 3/5/2018 4:28:36 PM 

Guest operation List Processes performed.                               Information 3/5/2018 4:28:31 PM 

Guest operation Start Program performed.                               Information 3/5/2018 4:28:31 PM 

Guest operation Create Temporary File performed.                    Information 3/5/2018 4:28:31 PM

This is the log that has been generated when the output is returned :

Guest operation Delete File performed.                                    Information 3/5/2018 4:27:52 PM 

Guest operation Initiate File Transfer From Guest performed. Information 3/5/2018 4:27:52 PM 

Guest operation List Processes performed.                               Information 3/5/2018 4:27:52 PM 

Guest operation List Processes performed.                              Information 3/5/2018 4:27:46 PM

Guest operation Start Program performed.                               Information 3/5/2018 4:27:46 PM 

Guest operation Create Temporary File performed.                  Information 3/5/2018 4:27:46 PM 

0 Kudos
LucD
Leadership
Leadership

So something is prohibiting the file upload from the guest OS to the script.

You are connecting (Connect-VIServer) on both client (10 & 2016) with the same credentials I assume?

You could try enable VMware Tools debugging inside the geuest OS (see KB1007873)

Perhaps that gives some more clues.

I'll do the same tests in my lab to see if I can replicate the issue.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
housamsmadi
Contributor
Contributor

Hi LucD,

as a test I cloned my Windows 10 VM that is working perfectly and installed the latest version of PowerCLI, and I got the same error.

When I tried to roll back to the version that is working (6.5.4.7155375 ) there were still some dependencies running higher version.

Is there a way that I can install PowerCLI with version 6.5.4.7155375 and make sure that the  dependencies are running the same old version that is working with me?

Here is a list with the versions that are working without troubles:

Name                                Version     
----                                -------     
VMware.DeployAutomation             6.5.1.6997673
VMware.ImageBuilder                 6.5.1.6997673
VMware.PowerCLI                     6.5.4.7155375
VMware.VimAutomation.Cis.Core       6.5.4.6983166
VMware.VimAutomation.Cloud          6.5.1.5375799
VMware.VimAutomation.Common         6.5.4.6979861
VMware.VimAutomation.Core           6.5.2.6234650
VMware.VimAutomation.HA             6.5.4.7147627
VMware.VimAutomation.HorizonView    7.1.0.5307191
VMware.VimAutomation.License        6.5.1.5375648
VMware.VimAutomation.Nsxt           2.0.0.6870461
VMware.VimAutomation.PCloud         6.5.1.5376282
VMware.VimAutomation.Sdk            1.0.0.5334677
VMware.VimAutomation.Srm            6.5.1.5374694
VMware.VimAutomation.Storage        6.5.4.7154886
VMware.VimAutomation.StorageUtility 1.1         
VMware.VimAutomation.Vds            6.5.1.5374428
VMware.VimAutomation.Vmc            6.5.4.7086404
VMware.VimAutomation.vROps          6.5.1.5375723
VMware.VumAutomation                6.5.1.5301639

Thanks in advanced!

Housam

0 Kudos
LucD
Leadership
Leadership

How did you do the roll-back?

Normally you can just remove the  folders with the current version, and then install the new version.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
housamsmadi
Contributor
Contributor

Problem sovled!

Actually I copied the folders from the working machine to the new one, and everything worked.

It seems to be the latest version.

Thanks for your help!

0 Kudos