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:
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
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
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.
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
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:
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
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
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)
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
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
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
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
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
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!