﻿<?xml version="1.0" encoding="utf-8"?>
<AdminArsenal.Export Code="PDQInventory" Name="PDQ Inventory" Version="18.2.12.0" MinimumVersion="15.0">
  <CustomTool>
    <CredentialsId value="null" />
    <RunAs>Admin</RunAs>
    <ScanAfter>ScanAfter</ScanAfter>
    <ScanProfileId value="2" />
    <SuccessCodesText>0</SuccessCodesText>
    <Timeout>00:03:00</Timeout>
    <WakeOnLan value="false" />
    <CustomToolType>Remote</CustomToolType>
    <CommandLine># Check for installed agent
$AppName = "PDQ Inventory Agent"
$Publisher = "PDQ.com"
foreach ($Architecture in "SOFTWARE", "SOFTWARE\Wow6432Node") { 
 $UninstallKeys = "HKLM:\$Architecture\Microsoft\Windows\CurrentVersion\Uninstall"
    if (Test-path $UninstallKeys) {
        Write-Output "Checking for $AppName in $UninstallKeys"
        $AgentInstallation = Get-ItemProperty -Path "$UninstallKeys\*" |
        Where-Object {$_.DisplayName -eq $AppName -and $_.Publisher -eq $Publisher}
        $AgentInstallations += $AgentInstallation
    }
}

# Uninstall agent
If($AgentInstallations){
    $AgentInstallations | ForEach-Object{
        Stop-Service "PDQ Inventory Agent" -Force
        Start-Sleep 5
        Write-Output "Uninstalling $($_.DisplayName) - $($_.PSChildName)"
        Start-Process -Wait -FilePath "MsiExec.exe" -ArgumentList "/X $($_.PSChildName) /qn /norestart"
    }
}
Else{
    Write-Output "No installations of $AppName found."
}

# Remove agent files
$AgentPaths = "$env:ProgramData\Admin Arsenal\PDQ Inventory Agent", "$env:ProgramFiles\Admin Arsenal\PDQ Inventory Agent", "${env:ProgramFiles(x86)}\Admin Arsenal\PDQ Inventory Agent", "$env:windir\AdminArsenal\InstallAgentStep"
foreach ($Path in $AgentPaths){
    if (Test-Path $Path) {
        Write-Output "Removing directory $Path"
        Remove-Item -Path $Path -Recurse
    }
}

# Remove registry key
$RegistryPath = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\PDQInventoryAgent"

if (Test-Path $RegistryPath) {
    Write-Output "Removing registry key $RegistryPath"
    Remove-Item -Path $RegistryPath -Recurse
}</CommandLine>
    <DefaultIconKey></DefaultIconKey>
    <LibraryToolId value="null" />
    <Modified value="null" />
    <ShellOpenMode>ToolWindowCaptureOutput</ShellOpenMode>
    <Mode>PowerShell</Mode>
    <Description></Description>
    <IconKey>Icon-PowerShell</IconKey>
    <KeyGesture></KeyGesture>
    <Title>Uninstall PDQ Inventory Agent</Title>
    <TypeName>CustomTool</TypeName>
  </CustomTool>
</AdminArsenal.Export>