Hi,
I am unable to uninstall the application using the invoke-command as below, please help
$serv = Get-Content ".\vms.txt"
$WPassword = "password"
$pass = ConvertTo-SecureString -AsPlainText $WPassword -Force
$Creds = New-Object System.Management.Automation.PSCredential ("admin", $pass)
$output = Invoke-Command -ComputerName $serv -Credential $Creds -ScriptBlock {
if (Test-Path -Path 'C:\Program Files (x86)\Notepad++\notepad++.exe'){
echo '32bit installed'
echo 'Uninstalling x86 Notepad++......'
& 'C:\Program Files (x86)\Notepad++\uninstall.exe' '/S'
} elseif (Test-Path -Path 'C:\Program Files\Notepad++\notepad++.exe'){
echo '64bit installed'
echo 'Uninstalling 64 bit Notepad++......'
& 'C:\Program Files\Notepad++\uninstall.exe' '/S'
} else {
"Notepad++ is not installed"
}
}
$output
This looks to be an issue with UAC.
You need to run this uninstall from an elevated prompt.
An alternative could be to have psexec.exe available on the target station.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Is there any output from the Invoke-Command?
If not, can you add a Start-Transcript to the code block?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
Output is
32bit installed
Uninstalling x86 Notepad++......
But when I login the actual machine, it is not getting uninstalled.
When I execute the below script directly on the remote computer, it works
if (Test-Path -Path 'C:\Program Files (x86)\Notepad++\notepad++.exe'){
echo '32bit installed'
echo 'Uninstalling x86 Notepad++......'
& 'C:\Program Files (x86)\Notepad++\uninstall.exe' '/S'
} elseif (Test-Path -Path 'C:\Program Files\Notepad++\notepad++.exe'){
echo '64bit installed'
echo 'Uninstalling 64 bit Notepad++......'
& 'C:\Program Files\Notepad++\uninstall.exe' '/S'
} else {
"Notepad++ is not installed"
}
This looks to be an issue with UAC.
You need to run this uninstall from an elevated prompt.
An alternative could be to have psexec.exe available on the target station.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
Thanks for assisting on this issue, most of the times, psexec gives error because of firewall issues and fails, I was able to resolve as below
$output = Invoke-Command -ComputerName $serv -Credential $Creds -ScriptBlock {start-process -filepath 'C:\Program Files (x86)\Notepad++\uninstall.exe' -ArgumentList '/S' -Verb runas -Wait}
As always, thanks a lot for your support and help