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:
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
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
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
Is UAC disabled?
Otherwise you will be getting the UAC prompt on the 'Runas'.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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:
Did you logon with the same account as the one specified on the Invoke-VMScript?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes same account is used for both operation.