Quantcast
Channel: VMware Communities : Discussion List - Automation Tools
Viewing all articles
Browse latest Browse all 9071

PowerShell remoting to install VMWare tools

$
0
0

Greetings

 

Admittedly this is probably more focused on PowerShell and less on VMware but VMware tools is the target.

 

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-ModuleVMware.VimAutomation.Cis.Core

Import-ModuleVMware.VimAutomation.Core

Import-ModuleVMware.VimAutomation.HA

Import-ModuleVMware.VimAutomation.Sdk

Import-ModuleVMware.VimAutomation.Storage

Import-ModuleVMware.VimAutomation.Vds

 

 

Connect-VIServervCenterserver.domain


$username="domain\username"

$SecurePassword=Read-Host-Prompt"Enter **DOMAIN** password"-AsSecureString

$Credentials=New-ObjectSystem.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-classWin32_CDROMDrive|selectDrive|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.


Viewing all articles
Browse latest Browse all 9071

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>