VMware Cloud Community
vin01
Expert
Expert

invoke operation fails

I am trying to install a hot fix on windows 7 machines but it is failing with below error.

Can someone help me by correcting the script.

$script = @'

`$code=wusa.exe C:\windows6.1-kb4499175-x64_3704acfff45ddf163d8049683d5a3b75e49b58cb.msu /quiet /norestart

function Elevate-Process {

  param (

  [string]`$exe,

  [string]`$arguments

  )

  `$startinfo = new-object System.Diagnostics.ProcessStartInfo

  `$startinfo.FileName = `$exe

  `$startinfo.Arguments = `$arguments

  `$startinfo.verb = "RunAs"

  `$process = [System.Diagnostics.Process]::Start(`$startinfo)

}

Elevate-Process -Exe powershell.exe -Arguments "-noninteractive -command &{$code}"

'@

foreach($vm in Get-VM 'SEW04VVM317' ) {

Invoke-VMScript -VM $vm.Name -GuestUser "admin" -GuestPassword "**" -ScriptText $script -ScriptType Powershell -ErrorAction Stop | Select -ExpandProperty ScriptOutput

}

Error:

pastedImage_1.png

Regards Vineeth.K
Reply
0 Kudos
7 Replies
LucD
Leadership
Leadership

When you use a here-string with single quotes, there is no variable substitution.
So there is no need to place a back-tick before the dollar signs.


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

Reply
0 Kudos
vin01
Expert
Expert

I have tried like this and script executed with out any errors but it is not initiating the wusa.exe process inside the guest OS.

$script = @'

$code= wusa.exe C:\windows6.1-kb4499175-x64_3704acfff45ddf163d8049683d5a3b75e49b58cb.msu /quiet /norestart

function Elevate-Process {

  param (

  [string]$exe,

  [string]$arguments

  )

  $startinfo = new-object System.Diagnostics.ProcessStartInfo

  $startinfo.FileName = $exe

  $startinfo.Arguments = $arguments

  $startinfo.verb = "RunAs"

  $process = [System.Diagnostics.Process]::Start($startinfo)

}

Elevate-Process -Exe powershell.exe -Arguments "-noninteractive -command &{$code}"

'@

$vm= Get-VM 'SEW04VVM317'

Invoke-VMScript -VM $vm.Name -GuestUser "admin" -GuestPassword "**" -ScriptText $script -ScriptType Powershell -ErrorAction Stop | Select -ExpandProperty ScriptOutput

Regards Vineeth.K
Reply
0 Kudos
vin01
Expert
Expert

I have tried like this and script executed with out any errors but it is not initiating the wusa.exe process inside the guest OS.

$script = @'

$code= wusa.exe C:\windows6.1-kb4499175-x64_3704acfff45ddf163d8049683d5a3b75e49b58cb.msu /quiet /norestart

function Elevate-Process {

  param (

  [string]$exe,

  [string]$arguments

  )

  $startinfo = new-object System.Diagnostics.ProcessStartInfo

  $startinfo.FileName = $exe

  $startinfo.Arguments = $arguments

  $startinfo.verb = "RunAs"

  $process = [System.Diagnostics.Process]::Start($startinfo)

}

Elevate-Process -Exe powershell.exe -Arguments "-noninteractive -command &{$code}"

'@

$vm= Get-VM 'SEW04VVM317'

Invoke-VMScript -VM $vm.Name -GuestUser "admin" -GuestPassword "**" -ScriptText $script -ScriptType Powershell -ErrorAction Stop | Select -ExpandProperty ScriptOutput

Regards Vineeth.K
Reply
0 Kudos
LucD
Leadership
Leadership

Is UAC disabled?

Otherwise you will be getting the UAC prompt on the 'Runas'.


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

Reply
0 Kudos
vin01
Expert
Expert

UAC is set to never notify.

If I try below variation inside the guest I can able to execute the cmd successfully and wusa.exe process will start for installation but when I pass scripttext using invoke-vmscript it executes without any error but inside the guestos wusa.exe process is not stating.

function Elevate-Process  {

param ([string]$exe = $(Throw "Pleave provide the name and path of an executable"),[string]$arguments)

$startinfo = new-object System.Diagnostics.ProcessStartInfo

$startinfo.FileName = $exe

$startinfo.Arguments = $arguments

$startinfo.verb = "RunAs"

$process = [System.Diagnostics.Process]::Start($startinfo)

}

Elevate-Process -Exe powershell.exe -Arguments "-noninteractive -command C:\windows6.1-kb4499175-x64_3704acfff45ddf163d8049683d5a3b75e49b58cb.msu /quiet /norestart"

Output:

pastedImage_4.png

Regards Vineeth.K
Reply
0 Kudos
LucD
Leadership
Leadership

Did you logon with the same account as the one specified on the Invoke-VMScript?


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

Reply
0 Kudos
vin01
Expert
Expert

Yes same account is used for both operation.

Regards Vineeth.K
Reply
0 Kudos