83 lines
2.9 KiB
PowerShell
83 lines
2.9 KiB
PowerShell
#requires -Version 7.0
|
|
<#
|
|
.SYNOPSIS
|
|
List Tanium Deploy Software Packages using Get-DeploySoftware.
|
|
Reads URL/token from config.json, initializes the session, then queries by:
|
|
- All | ByName | ByID | ByVendor | ByCommand | NameRegex
|
|
and displays results in Out-GridView (fallback to console table).
|
|
#>
|
|
|
|
# =========================
|
|
# Block 1 - Prerequisites
|
|
# =========================
|
|
$ErrorActionPreference = 'Stop'
|
|
try { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 } catch {}
|
|
Import-Module Redden-TanREST -Force
|
|
|
|
# =========================
|
|
# Block 2 - Load config & init session
|
|
# =========================
|
|
$configPath = Join-Path $PSScriptRoot 'config.json'
|
|
$TempXml = Join-Path $env:TEMP 'tanium-session-tmp.apicred'
|
|
|
|
if (-not (Test-Path $configPath)) { throw "Configuration file not found: $configPath" }
|
|
|
|
Write-Host "Reading configuration from: $configPath"
|
|
$config = Get-Content -Path $configPath -Raw | ConvertFrom-Json
|
|
$TaniumUrl = $config.TaniumUrl
|
|
$TaniumToken = $config.TaniumApiToken
|
|
|
|
if ([string]::IsNullOrWhiteSpace($TaniumUrl) -or [string]::IsNullOrWhiteSpace($TaniumToken)) {
|
|
throw "Both TaniumUrl and TaniumApiToken must be provided (config.json or environment variables)."
|
|
}
|
|
if ($TaniumUrl -match '^https?://') {
|
|
$TaniumUrl = $TaniumUrl -replace '^https?://','' -replace '/+$',''
|
|
Write-Host "Normalized TaniumUrl to host: $TaniumUrl"
|
|
}
|
|
|
|
$ExportObject = @{
|
|
baseURI = $TaniumUrl
|
|
token = ($TaniumToken | ConvertTo-SecureString -AsPlainText -Force)
|
|
}
|
|
$ExportObject | Export-Clixml -Path $TempXml
|
|
|
|
Write-Host "Initializing Tanium session..."
|
|
Initialize-TaniumSession -PathToXML $TempXml
|
|
Write-Host "Tanium session initialized."
|
|
|
|
# =========================
|
|
# Block 3 - Queries
|
|
# =========================
|
|
#Get-DeploySoftware -All | Out-GridView
|
|
#Get-Role -All | Out-GridView
|
|
#Get-UserAndGroupDetail
|
|
|
|
# -- Out-GridView available? (PS7 tip: Install-Module Microsoft.PowerShell.GraphicalTools)
|
|
$hasOGV = [bool](Get-Command Out-GridView -ErrorAction SilentlyContinue)
|
|
|
|
Write-Host "Fetching Users..." -ForegroundColor Cyan
|
|
$users = Get-User -All | Sort-Object displayName, username
|
|
if ($hasOGV) {
|
|
$users | Out-GridView -Title "Tanium Users (All)" -Wait
|
|
} else {
|
|
$users | Format-Table id, displayName, username, email -AutoSize
|
|
Write-Host "(Out-GridView not available; showing table output)" -ForegroundColor Yellow
|
|
}
|
|
|
|
Write-Host "Fetching User Groups..." -ForegroundColor Cyan
|
|
$groups = Get-UserGroup -All | Sort-Object name
|
|
if ($hasOGV) {
|
|
$groups | Out-GridView -Title "Tanium User Groups (All)" -Wait
|
|
} else {
|
|
$groups | Format-Table id, name, description -AutoSize
|
|
Write-Host "(Out-GridView not available; showing table output)" -ForegroundColor Yellow
|
|
}
|
|
|
|
# =========================
|
|
# Block 5 - Cleanup
|
|
# =========================
|
|
if (Test-Path $TempXml) {
|
|
Remove-Item $TempXml -Force -ErrorAction SilentlyContinue
|
|
Write-Host "Temporary CLIXML removed: $TempXml"
|
|
}
|