Question:
I am trying to run a exe on remote machines which would basically uninstall a product agent. below is the code:
1 2 3 4 5 6 7 8 9 10 |
$test = Get-Content PC.txt foreach ($a in $test) { $curr = Get-Location Set-Location \\$a\Admin$\System32\CCMSetup .\ccmsetup.exe /uninstall Set-Location $curr } |
It doesn’t work. I ended up removing the program from the host computer itself 🙂
Alternate Option: I created a batch file with the command line:
1 2 3 4 |
cd C:\Windows\System32\ccmsetup ccmsetup /uninstall exit |
It seems the above can also be achieved using Invoke-Command.
1 2 |
Invoke-Command -ComputerName $client -FilePath UninstallCCM.cmd |
Apparently, it does not accept batch file. I would like to keep it as simple as possible.
Currently I am using PSExec for installing and uninstalling the program. Do I need to enable PS Remoting (WinRM) on every remote machine on whom I need to execute scripts using PowerShell?
Can someone please help? Thanks in advance.
Answer:
This command should execute successfully:
1 2 |
Invoke-Command -ComputerName $client -ScriptBlock { cd C:\Windows\System32\ccmsetup; ccmsetup /uninstall} -Credential $(Get-Credential) -Authentication CredSSP |
but you will need to enable CredSSP authentication on all machines by running these two commands on each machine:
1 2 3 |
Enable-WsManCredSSP -Role Server -Force Enable-WSManCredSSP -Role Client -DelegateComputer * -Force |