Public/Uninstall-MicrosoftSilverlight.ps1

function Uninstall-MicrosoftSilverlight {
    <#
    .SYNOPSIS
        Uninstalls Microsoft Silverlight using its registered uninstaller.
    .DESCRIPTION
        Searches the 64-bit and 32-bit uninstall registry hives for Microsoft Silverlight,
        then invokes the uninstall string found in the registry. If Silverlight is not found
        in the registry no action is taken.
    .INPUTS
        None. Parameters must be supplied directly.
    .OUTPUTS
        None.
    .PARAMETER ComputerName
        The target computer. Defaults to the local machine.
    .EXAMPLE
        Uninstall-MicrosoftSilverlight

        Uninstalls Microsoft Silverlight from the local machine if it is present.
    .EXAMPLE
        Uninstall-MicrosoftSilverlight -ComputerName 'Workstation01'

        Uninstalls Microsoft Silverlight from Workstation01 if it is present.
    .NOTES
        Requires Administrator privileges.
        The uninstall command is sourced directly from the registry and may launch an interactive
        dialog depending on how Silverlight was installed.
        Remote operations require WinRM to be configured on the target machine.
    #>


    [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')]
    [OutputType([void])]

    param (
        [Parameter(Mandatory = $false)]
        [string]$ComputerName = $env:COMPUTERNAME
    )

    $isLocal = ($ComputerName -ieq $env:COMPUTERNAME) -or
               ($ComputerName -ieq 'localhost') -or
               ($ComputerName -eq '127.0.0.1')

    if ($PSCmdlet.ShouldProcess($ComputerName, 'Invoke Microsoft Silverlight uninstaller')) {
        $work = {
            $uninstallKeys = @(
                'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall',
                'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
            )

            $uninstallStrings = $uninstallKeys | ForEach-Object {
                Get-ChildItem -Path $_ -ErrorAction SilentlyContinue
            } | ForEach-Object {
                Get-ItemProperty -Path $_.PSPath -ErrorAction SilentlyContinue
            } | Where-Object {
                $_.DisplayName -like 'Microsoft Silverlight'
            } | Select-Object -ExpandProperty UninstallString

            if (-not $uninstallStrings) {
                Write-Verbose 'Microsoft Silverlight was not found in the registry. Nothing to uninstall.'
                return
            }

            foreach ($uninstallString in $uninstallStrings) {
                Write-Verbose "Invoking: $uninstallString"
                & $uninstallString
            }
        }

        if ($isLocal) {
            & $work
        } else {
            Invoke-Command -ComputerName $ComputerName -ScriptBlock $work
        }

        Write-Verbose "Microsoft Silverlight uninstall invoked on '$ComputerName'."
    }
}