Functions/Uninstall-GraylogSidecar.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<#
    .SYNOPSIS
        Uninstall the Graylog Sidecar.
 
    .DESCRIPTION
        Use the uninstall.exe in the Sidecar program folder to remove the
        current installation.
 
    .EXAMPLE
        PS C:\> Uninstall-GraylogSidecar
        Uninstall the Graylog Sidecar.
#>

function Uninstall-GraylogSidecar
{
    [CmdletBinding()]
    [OutputType([System.String])]
    param ()

    # # Uninstall the application
    Write-Verbose 'Uninstall Graylog Sidecar application'
    $appUninstallResult = (& 'C:\Program Files\Graylog\sidecar\uninstall.exe' /S)
    $appUninstallResult | Write-Verbose

    # Wait for the uninstall to complete. To be sure, add a sleep second after
    # scanning the installation status.
    $appInstallState = $false
    for ($c = 0; $c -lt 300 -and $appInstallState; $c++)
    {
        $appInstallState = -not [System.String]::IsNullOrWhiteSpace((Get-GraylogSidecarVersion))
        Start-Sleep -Seconds 1
    }
}