Here is an example how to uninstall Microsoft Office Project Professional 2010 remotely.
This script include these steps:
1. Getting the list of computers and performs actions following actions on them
2. Check if it is pinging, if there is installed Microsoft Office Project Professional 2010 using wmi
3. Creates a job with invoke-command for particular computer with these steps:
a. Creates file config.xml in C:\Windows\Temp (for silent uninstall command)
b. Checks remote computer architecture (x32 or x64)
c. Runs this command which performs silent uninstall: “C:\Program Files\Common Files\Microsoft Shared\OFFICE14\Office Setup Controller\setup.exe” /UNINSTALL PRJPRO /CONFIG “C:\Windows\Temp\config.xml”
d. Register Event: if changes the job state than performs checking if this computer still has Microsoft Office Project Professional 2010 in installed programs
c. Depending on result in checking existence of Microsoft Office Project Professional 2010 after uninstall command it writes to the host if job passed or failed.
"PC01" | ForEach-Object {
if (Test-Connection $_ -Quiet -Count 1)
{
$pcname=$_
if (Get-WmiObject win32_product -ComputerName $pcname -Filter "Caption='Microsoft Office Project Professional 2010'")
{
$pcname
$job = Invoke-Command -ComputerName $pcname -AsJob -ScriptBlock `
{
New-Item -Path C:\Windows\Temp -Name config.xml -ItemType "file" -Value `
'
'
if([IntPtr]::Size -eq 4)
{
Start-Process -PassThru -Verb RunAs -FilePath "C:\Program Files\Common Files\Microsoft Shared\OFFICE14\Office Setup Controller\setup.exe" -ArgumentList '/UNINSTALL PRJPRO /CONFIG "C:\Windows\Temp\config.xml"' -Wait
}
Else
{
Start-Process -PassThru -Verb RunAs -FilePath "C:\Program Files (x86)\Common Files\Microsoft Shared\OFFICE14\Office Setup Controller\setup.exe" -ArgumentList '/UNINSTALL PRJPRO /CONFIG "C:\Windows\Temp\config.xml"' -Wait
}
}
Register-ObjectEvent $job StateChanged -Action `
{
if (Get-WmiObject win32_product -Filter "Caption='Microsoft Office Project Professional 2010'")
{
Write-Host "Job #$($sender.Id) ($($sender.Location)) failed" -ForegroundColor Red
}
else
{
Write-Host "Job #$($sender.Id) ($($sender.Location)) completed" -ForegroundColor Green
}
}
}
}
}
P.S. Please take into consideration that PowerShell Remoting should be enabled on all computers where do you want to perform uninistall: