$VIPREAgentGUID = @(
"C6AB2467-7C8B-4523-A18C-C466049DBA4C",
"345888D4-199F-48D1-A89C-694B48F2F5A3",
"1D9E6C77-07CA-43B1-9A25-BF4FA0EA8758",
"077A97DD-E63E-4A4F-B39C-E1111AA9E151",
"28090F18-50E3-4AE6-B258-D27DEC2404D9",
"3D81A81B-477F-4D0D-8B3C-599E032CF283",
"2B43966F-3C72-4D34-AB5A-2D35F5320C4C",
"0C92648E-DC79-4A1E-A63A-FA7492E8CDA7",
"2645C2A8-4700-46F9-B2F7-A0E826DBCF91",
"56CA3334-8B72-48D1-81E7-3EF5243E45D5",
"8B2C9073-C948-4033-93EF-E7F781E43E35",
"1BDEA9D9-7988-4BC2-8DE3-2AE4B6E65969",
"82FB46C5-494D-41A8-81C4-E2CC094169BE",
"BAA1CAE8-8E7B-4000-AC56-38AC8BB7506A",
"CC1CEA69-B7AF-47EE-AB64-68B7A1E2F3CF",
"D685DD76-77A3-4661-B9F0-7DAE2D651260",
"B0783CD0-27C6-49B4-9905-AC3A6437F5A8",
"9CE81981-648E-4C9D-AC2F-6B129071903F",
"628B718E-65C3-47C8-B4C8-A86CA1B42F69",
"6A68DC82-9FFD-41EB-91BA-86A4CECF29C0",
"092D4B8A-D0BA-4D2D-A690-78357FEBBC38",
"3DF87105-29CA-4F06-9ACC-1745AFE49555",
"39A086B2-07D6-430B-AE5E-B8AC1CC843A7",
"E10809C0-E65F-4493-A31B-3F86DB6E9E2A",
"9D544611-F437-4153-913E-91CE036583CC",
"39A086B2-07D6-430B-AE5E-B8AC1CC843A7")

foreach ($guid in $VIPREAgentGUID) {
    #Start-Process "msiexec.exe" -ArgumentList "/x {${guid}} /qf /l*v `"${Env:TEMP}\VIPRE_MsiUninstall_${guid}.log`" REMOVE=ALL" -Wait
}

$VIPREServices = @(
"GFIARK",
"GFIUTIL",
"SBAMSvc",
"SBAPHD",
"SBAPIFS",
"SBEMI",
"SBFW",
"SBFWIMCL",
"SBFWIMCLMP",
"SBHIPS",
"SBPIMSVC",
"SBRE",
"SBTIS",
"SBWTIS",
"VipreEdgeProtection")

foreach ($service in $VIPREServices) {
    Start-Process "net.exe" -ArgumentList "stop ${service}" -Wait
}

foreach ($service in $VIPREServices) {
    Start-Process "sc.exe" -ArgumentList "delete ${service}" -Wait
}

$VIPREGUIDRegistryPaths = @(
"HKLM:Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall",
"HKLM:Software\Microsoft\Windows\CurrentVersion\Uninstall")
$VIPRERegistryPaths = @(
"HKLM:Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{C1D1FC57-3EB9-4B21-BCA3-F1C927508200}",
"HKLM:Software\Microsoft\Windows\CurrentVersion\Uninstall\{C1D1FC57-3EB9-4B21-BCA3-F1C927508200}",
"HKLM:Software\Wow6432Node\Sunbelt Software\Sunbelt Enterprise Agent",
"HKLM:Software\Sunbelt Software\Sunbelt Enterprise Agent",
"HKLM:Software\Wow6432Node\GFI Software\GFI Business Agent",
"HKLM:Software\GFI Software\GFI Business Agent",
"HKLM:Software\Wow6432Node\GFI Software\Deployment",
"HKLM:Software\GFI Software\Deployment",
"HKLM:Software\Wow6432Node\SBAMSvc",
"HKLM:Software\SBAMSvc",
"HKLM:Software\Wow6432Node\SBAMSvcVolatile",
"HKLM:Software\SBAMSvcVolatile",
"HKLM:Software\Wow6432Node\VIPRE Business Agent",
"HKLM:Software\VIPRE Business Agent")

foreach ($path in $VIPREGUIDRegistryPaths) {
    foreach ($guid in $VIPREAgentGUID) {
        if (Test-Path "${path}\${guid}") {
            Remove-Item "${path}\${guid}" -Recurse
        }
    }
}

foreach ($path in $VIPRERegistryPaths) {
    if (Test-Path "${path}") { Remove-Item "${path}" -Recurse }
}

$VIPREProductFeature = @(
"0C90801EF56E39443AB1F368BDE6E9A2",
"116445D9734F351419E319EC305638CC",
"18918EC9E846D9C4CAF2B621091709F3",
"2B680A936D70B034EAE58BCAC18C347A",
"3709C2B8849C330439FE7E7F184EE353",
"4333AC6527B81D84187EE35F42E3545D",
"4D888543F9911D848AC996B4842F5F3A",
"50178FD3AC9260F4A9CC7154FA4E5955",
"5C64BF28D4948A14184C2ECC901496EB",
"67DD586D3A7716649B0FD7EAD2562106",
"7642BA6CB8C732541AC84C6640D9ABC4",
"77C6E9D1AC701B34A952FBF40AAE7885",
"81F090823E056EA42B852DD7CE42409D",
"8A2C546200749F642B7F0A8E62BDFC19",
"8EAC1AABB7E80004CA6583CAB87B05A6",
"96AEC1CCFA7BEE74BA46867B1A2E3FFC",
"9D9AEDB188972CB4D83EA24E6B6E9596",
"B18A18D3F774D0D4B8C395E930C22F38",
"C21346408A6123D4299DD1D723899DC1",
"C928BABD4AA3D694D99624F210BD8691",
"DD79A770E36EF4A43BC91E11A19A1E15",
"E84629C097CDE1A46AA3AF47298EDC7A",
"F66934B227C343D4BAA5D2535F23C0C4")

$VIPREProductFeatureKeys = @(
"HKLM\Software\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products",
"HKLM\Software\Classes\Installer\Features",
"HKLM\Software\Classes\Installer\Products",
"HKCR\Installer\Products",
"HKCR\Installer\Features")

foreach ($path in $VIPREProductFeatureKeys) {
    foreach ($productfeature in $VIPREProductFeature) {
        if (Test-Path "${path}\${productfeature}") {
            Remove-Item "${path}\${productfeature}" -Recurse
        }
    }
}

if (Test-Path "${Env:ProgramFiles(x86)}\VIPRE Business Agent\SBAMScanShellExt.dll") {
    cd "${Env:ProgramFiles(x86)}\VIPRE Business Agent"
    Start-Process "RegSvr32.exe" -ArgumentList "/u SBAMScanShellExt.dll" -Wait
}

if (Test-Path "${Env:ProgramFiles}\VIPRE Business Agent\SBAMScanShellExt.dll") {
    cd "${Env:ProgramFiles}\VIPRE Business Agent"
    Start-Process "RegSvr32.exe" -ArgumentList "/u SBAMScanShellExt.dll" -Wait
}

$VIPREDirectoryPaths = @(
"${Env:ProgramFiles}\VIPRE Business Agent",
"${Env:ProgramFiles}\GFI Software\Deployment",
"${Env:ProgramFiles}\GFI Software\GFIAgent",
"${Env:ProgramFiles}\GFI Software\LanGuard 10",
"${Env:ProgramFiles}\Sunbelt Software\Deployment",
"${Env:ProgramFiles}\Sunbelt Software\SBEAgent",
"${Env:ProgramFiles(x86)}\VIPRE Business Agent",
"${Env:ProgramFiles(x86)}\GFI Software\Deployment",
"${Env:ProgramFiles(x86)}\GFI Software\GFIAgent",
"${Env:ProgramFiles(x86)}\GFI Software\LanGuard 10",
"${Env:ProgramFiles(x86)}\Sunbelt Software\Deployment",
"${Env:ProgramFiles(x86)}\Sunbelt Software\SBEAgent",
"${Env:ProgramData}\VIPRE Business Agent",
"${Env:ProgramData}\GFI Software\Antimalware",
"${Env:ProgramData}\GFI Software\LanGuard 10",
"${Env:ProgramData}\Sunbelt Software\Antimalware")
foreach ($path in $VIPREDirectoryPaths) {
    if (Test-Path "${path}") {
        Remove-Item "${path}" -Recurse
    }
}

$VIPREEngineFiles = @(
"${Env:WinDir}\system32\drivers\sbaphd.sys"
"${Env:WinDir}\system32\drivers\sbapifs.sys",
"${Env:WinDir}\system32\drivers\SbFw.sys",
"${Env:WinDir}\system32\drivers\SbFwIm.sys",
"${Env:WinDir}\system32\drivers\sbhips.sys",
"${Env:WinDir}\system32\drivers\SBREDrv.sys",
"${Env:WinDir}\system32\drivers\sbtis.sys",
"${Env:WinDir}\system32\drivers\sbwtis.sys",
"${Env:WinDir}\system32\drivers\gfiark.sys",
"${Env:WinDir}\system32\drivers\gfiutil.sys")
foreach ($file in $VIPREEngineFiles) {
    if (Test-Path "${file}") {
        Remove-Item "${file}" -Force
    }
}