Pages

Monday, 9 February 2026

detection script

# ===============================
# Detection Script - Visio Usage
# ===============================

$daysThreshold = 90
$prefetchPath = Join-Path $env:SystemRoot 'Prefetch'

# Common Visio C2R paths
$visioExePaths = @(
    "$env:ProgramFiles\Microsoft Office\root\Office16\VISIO.EXE",
    "$env:ProgramFiles(x86)\Microsoft Office\root\Office16\VISIO.EXE"
)

# ---- Check if Visio is installed ----
$visioInstalled = $false
foreach ($path in $visioExePaths) {
    if (Test-Path -LiteralPath $path) {
        $visioInstalled = $true
        break
    }
}

if (-not $visioInstalled) {
    Write-Output "Compliant: Visio is not installed."
    exit 0
}

# ---- Check Prefetch usage ----
try {
    $prefetchFiles = Get-ChildItem -Path $prefetchPath -Filter "VISIO.EXE-*.pf" -ErrorAction Stop
} catch {
    $prefetchFiles = $null
}

if (-not $prefetchFiles) {
    Write-Output "Compliant: Visio installed but Prefetch file not found. Usage cannot be determined."
    exit 0
}

# ---- Determine last usage ----
$lastRunTime = ($prefetchFiles | Sort-Object LastWriteTime -Descending | Select-Object -First 1).LastWriteTime
$daysSinceLastRun = [int](New-TimeSpan -Start $lastRunTime -End (Get-Date)).TotalDays

if ($daysSinceLastRun -le $daysThreshold) {
    Write-Output "Compliant: Visio used $daysSinceLastRun day(s) ago."
    exit 0
} else {
    Write-Output "Non-Compliant: Visio last used $daysSinceLastRun day(s) ago (Threshold: $daysThreshold)."
    exit 1
}

detection script

# =============================== # Detection Script - Visio Usage # =============================== $daysThreshold = 90 $prefetchPath = ...

Search This Blog