Greetings
Admittedly this is probably more focused on PowerShell and less on VMware but VMware tools is the target. :smileyhappy:
I am attempting to write a script to install VMware tools remotely onto VMs that don't have VMware tools installed.
So far I have the below...
Import-Module VMware.VimAutomation.Cis.Core
Import-Module VMware.VimAutomation.Core
Import-Module VMware.VimAutomation.HA
Import-Module VMware.VimAutomation.Sdk
Import-Module VMware.VimAutomation.Storage
Import-Module VMware.VimAutomation.Vds
Connect-VIServer vCenterserver.domain
$username = "domain\username"
$SecurePassword = Read-Host -Prompt "Enter **DOMAIN** password" -AsSecureString
$Credentials = New-Object System.Management.Automation.PSCredential `
-ArgumentList $UserName, $SecurePassword
$VM = "Test01"
Get-vm $VM | Dismount-Tools
Get-vm $VM | Mount-Tools
$RMsession = New-PSSession -ComputerName $VM -Credential $Credentials
Invoke-Command -Session $RMSession -ScriptBlock {$CDRom = Get-WmiObject -class Win32_CDROMDrive | select Drive | ForEach {$_.Drive}}
Invoke-Command -Session $RMSession -ScriptBlock {$Subpath = '\setup.exe -s -v-qn ADDLOCAL=ALL REBOOT=R'}
Invoke-Command -Session $RMSession -ScriptBlock {$ExecuteEXE = Join-Path -Path $CDRom -ChildPath $Subpath}
Invoke-Command -Session $RMSession -ScriptBlock {start-process $executeEXE}
exit
Remove-PSSession *
Disconnect-VIServer * -Confirm:$False
I have confirmed that $executeEXE does indeed = Z:\setup.exe -s -v-qn ADDLOCAL=ALL REBOOT=R
When I run the script in the ISE I get :
Start-Process : This command cannot be executed due to the error: The system cannot find the file specified.
At line:1 char:14
+ start-process <<<< $executeEXE
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand
Admittedly I'm very inexperienced with PowerShell remoting.
It would appear that when I execute the whole script it doesn't seem to actually be invoking the command on the remote computer but rather on the local computer. The VMware tools are mounting and the path in $executeEXE is 100% correct and the PSSession is also definitely open but no magic?
Any guidance would be greatly appreciated.