I need a solution
Hi,
I'm trying to use the below powershell script that i came across (thank you - Craig Beetlestone) to uninstall Java Development Kit installs on client computers in my environment.
#Find all Java products excluding the auto updater which actually gets uninstalled when the main install is removed.
[array]$javas=Get-WmiObject -query "select * from win32_Product where (Name like 'Java %' or Name like 'Java(TM)%') and Name <> 'Java Auto Updater'"
if ($javas.count -gt 0)
{
write-host "Java is already Installed" -ForegroundColor Yellow
#Get all the Java processes and kill them. If java is running and the processes aren't killed then this script will invoke a sudden reboot.
[array]$processes=Get-Process -Name "Java*"
if ($processes.Count -gt 0){foreach ($myprocess in $processes){$myprocess.kill()}}
#Loop through the installed Java products.
foreach($java in $javas){
write-host "Uninstalling "$java.name -ForegroundColor Yellow
$java.Uninstall()
}
}
When i setup a powershell script task and test run it on a client machine - the task fails with return code 1, when i try and manually run the task on the client through powershell - the task has no issues executing.
I've even ran the "enable powershell signing policy" task - successfully.
What am i doing wrong here? any help is much appreciated.
Thank you
cheers,
Vikram