Uninstalling MSOffice Patches with msiexec

Good Morning all,

I am attempting to uninstall some MSOffice Patches by running the below script I created on our clients using LANDESK but I am getting this error in Powershell V2:

Method invocation failed because [System.Object[]] doesn't contain a method named 'IndexOf'.

At C:\LD\Infrastructure\Packages\Uninstalls\Uninstall Patch\Uninstall-KB4461529.ps1:22 char:40

+ $x64PackageGUID[$x64ProductGUID.IndexOf <<<< ($PackageName)]

    + CategoryInfo          : InvalidOperation: (IndexOf:String) [], RuntimeException

    + FullyQualifiedErrorId : MethodNotFound

Sorry should have checked before posting:

System.Array instances do have an .IndexOf() method via an explicit implementation of the IList.IndexOf() interface method.

Up to PSv2, such explicit interface implementations were not accessible at all.

In PSv3+, explicit interface implementations are available directly on the implementing type, without the need to reference the interface, so your code would work, but Nacht’s answer is still the better solution in the case at hand.

<hr />

[pre]$ScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
Start-Transcript -Path “$ScriptRoot\UninstallPatch.txt”

$x86ProductGUID = @("{90140000-0012-0000-0000-0000000FF1CE}","{90140000-0012-0000-0000-0000000FF1CE}")
$x86PackageGUID = @("{0794FAB0-FFAE-4924-BFE8-BAF431F0DCB7}","{8DC35D91-704D-40D5-AB57-F0B60C22BB8B}")
$x64ProductGUID = @("{90140000-0012-0000-1000-0000000FF1CE}","{90140000-001A-0409-1000-0000000FF1CE}")
$x64PackageGUID = @("{35DAF14F-8627-48C8-A5E2-F99B993C01DB}","{5E114373-6A5F-413B-9C92-B66196F42135}")

Get-Service UI0Detect -ErrorAction SilentlyContinue | Stop-Service -ErrorAction SilentlyContinue #Stop the interactive services popup from displaying

if ($ENV:PROCESSOR_ARCHITECTURE -eq “x86”)
{
ForEach ($PackageName in $x86ProductGUID)
{
$Uninstall = (Start-Process -FilePath “msiexec.exe” -ArgumentList “/package `”$PackageName`" /uninstall `"$x86PackageGUID[$x86ProductGUID.IndexOf($PackageName)]`" /lv `"$ScriptRoot$($x86PackageGUID[$x86ProductGUID.IndexOf($PackageName)]).txt`" /qn /quiet /norestart" -Wait -Passthru).ExitCode #Returns the exit code of MSIExec
}
}
else
{
ForEach ($PackageName in $x64ProductGUID)
{
$Uninstall = (Start-Process -FilePath “msiexec.exe” -ArgumentList “/package `”$PackageName`" /uninstall `"$x64PackageGUID[$x64ProductGUID.IndexOf($PackageName)]`" /l
v `"$ScriptRoot$($x64PackageGUID[$x64ProductGUID.IndexOf($PackageName)]).txt`" /qn /quiet /norestart" -Wait -Passthru).ExitCode #Returns the exit code of MSIExec
}
}

Stop-Transcript
exit $Uninstall #Required so LANDESK returns the correct error code from the Powershell script[/pre]

You can use hashtables,

$r = @{col1='val1' ; col2='val2'}
$t = 'col2'
$r.$t