VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Invoke-command is not working on VM

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

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

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"

}

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

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 Smiley Happy

0 Kudos