VMware Cloud Community
esxi1979
Expert
Expert

powercli to install vmware tools on windows 7

Hello,

i need to install vmware tools on few windows 7 vms

i came across

https://communities.vmware.com/servlet/JiveServlet/previewBody/12413-102-3-13329/VMware%20Tools%20-%...

ie

msiexec /i "VMware Tools.msi" ADDLOCAL=ALL REMOVE="Hgfs,WYSE,GuestSDK,vmdesched" /qn /l* C:\temp\toolsinst.log /norestart

Also something of sort below ..

https://gist.github.com/sneal/eeb52e859186ba44163d

(New-Object System.Net.WebClient).DownloadFile($download_url, "c:\windows\temp\$iso_name")
&c:\7-zip\7z.exe x "c:\windows\temp\$iso_name" -oc:\windows\temp\vmware -aoa | Out-Host

&c:\windows\temp\vmware\setup.exe /S /v`"/qn REBOOT=R`" |


Out-Host

i have used,

Mount-Tools,

And have mounted the ISO

Can somehow we can do this automation with powercli or powershell ?

I want to use domain id & if that does not work a local admin account to comeplete the install.

Reply
0 Kudos
21 Replies
LucD
Leadership
Leadership

When the ISO is mounted in the VM, you could use the Invoke-Command cmdlet with the ComputerName parameter, to remotely start the setup.exe.


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

Reply
0 Kudos
esxi1979
Expert
Expert

LucD

I found below in our forum ..

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

$username =  "xx"

$password = "xx" | ConvertTo-SecureString -asPlainText -Force

$Credentials = New-Object System.Management.Automation.PSCredential ($username,$password)

 

   $VM = "xx"

   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}

==

Err

New-PSSession : One or more computer names are not valid. If you are trying to pass a URI, use the -ConnectionUri parameter, or pass URI objects instead of strings.

At line:1 char:17

+    $RMsession = New-PSSession -ComputerName $VM -Credential $Credentials

+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidArgument: (System.String[]:String[]) [New-PSSession], ArgumentException

    + FullyQualifiedErrorId : PSSessionInvalidComputerName,Microsoft.PowerShell.Commands.NewPSSessionCommand

===

Any suggestion Please 

Reply
0 Kudos
esxi1979
Expert
Expert

PowerCLI C:\>    $RMsession = New-PSSession -ComputerName $VM -Credential $Credentials

New-PSSession : [xx-xx] Connecting to remote server xx-xx failed with the following error message : WinRM cannot complete the operati

At line:1 char:17

+    $RMsession = New-PSSession -ComputerName $VM -Credential $Credentials

+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTransportException

    + FullyQualifiedErrorId : WinRMOperationTimeout,PSSessionOpenFailed

Above is new err

Reply
0 Kudos
esxi1979
Expert
Expert

fixed with

https://technet.microsoft.com/en-us/magazine/ff700227.aspx

now i get the err

This command cannot be executed due to the error: The system cannot find the file specified.

    + CategoryInfo          : InvalidOperation: (:) [Start-Process], InvalidOperationException

    + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand

    + PSComputerName        : xx-xx

Reply
0 Kudos
esxi1979
Expert
Expert

WinRM is all set

I tested that works fine with

Invoke-Command -ComputerName  $VM -Credential $Credentials  -ScriptBlock { Get-ChildItem C:\ }

Reply
0 Kudos
LucD
Leadership
Leadership

Is the CD available inside the guest OS after the Mount-Tools cmdlet?

From the error it looks it isn't.


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

Reply
0 Kudos
esxi1979
Expert
Expert

It is available

Reply
0 Kudos
esxi1979
Expert
Expert

i can see files

PowerCLI C:\> Invoke-Command -ComputerName  $VM -Credential $Credentials  -ScriptBlock { Get-ChildItem D:\ }

    Directory: D:\

Mode                LastWriteTime     Length Name

----                -------------     ------ ----

d----         8/20/2015   4:08 AM            Program Files

--r--         8/20/2015   4:08 AM     599232 VMwareToolsUpgrader.exe

--r--         8/20/2015   4:08 AM      55802 autorun.ico

--r--         8/20/2015   4:08 AM        100 autorun.inf

--r--         8/20/2015   4:08 AM         23 certified.txt

--r--         8/20/2015   4:08 AM       2953 manifest.txt

--r--         8/20/2015   4:08 AM   38275672 setup.exe

--r--         8/20/2015   4:08 AM   49833632 setup64.exe

Reply
0 Kudos
LucD
Leadership
Leadership

The error seems to be indicating that the setup.exe is not found.

Could you show the script/commands you are using?


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

Reply
0 Kudos
esxi1979
Expert
Expert

not clear what you need

but the script is below one

   $VM = "xx"

   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}

Reply
0 Kudos
LucD
Leadership
Leadership

Can you try like this?

$VM = "xx"

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}

    $setExe = '\setup.exe'

    $arguments = '-s -v-qn ADDLOCAL=ALL REBOOT=R'

    $ExecuteEXE = Join-Path -Path $CDRom -ChildPath $setExe

    Start-Process -FilePath $executeEXE -ArgumentList $arguments

}


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

Reply
0 Kudos
esxi1979
Expert
Expert

LucD

This time the script ran with no err

But the tools are not installed

I waited for 15 min now.

i did not see in "active task" any message saying tools are being installed

Reply
0 Kudos
LucD
Leadership
Leadership

Can you try running the lines in the scriptblock directly inside the guest OS?

I'm wondering if there might be a prompt or a message, that makes the remote job hang as well


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

Reply
0 Kudos
esxi1979
Expert
Expert

LucD

Sorry for delay,

I kept a login on the box & ran the script

It was stuck at attached

Reply
0 Kudos
esxi1979
Expert
Expert

i adjusted auto play options in control pannel manually & then i see below

Reply
0 Kudos
LucD
Leadership
Leadership

Perhaps I was not clear, but I wanted to see the setup.exe being started form a command prompt or PowerShell prompt, with the same parameters you are passing to the Invoke-VMScript.


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

Reply
0 Kudos
esxi1979
Expert
Expert

i mounted the cdrom & ran directly on OS

    $CDRom = Get-WmiObject -class Win32_CDROMDrive | select Drive | ForEach {$_.Drive}

    $setExe = '\setup.exe'

    $arguments = '-s -v-qn ADDLOCAL=ALL REBOOT=R'

    $ExecuteEXE = Join-Path -Path $CDRom -ChildPath $setExe

    Start-Process -FilePath $executeEXE -ArgumentList $arguments

No err but tools are not installed

Reply
0 Kudos
esxi1979
Expert
Expert

See attached

Reply
0 Kudos
LucD
Leadership
Leadership

Ok, leave out the 'qn' parameter, that way the installation will not be silent anymore.

And you should see what is happening


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

Reply
0 Kudos