Skip to content
Caleb SmithCyberSecurityWithSmitti
Browse PowerShell example contentPowerShell example

Endpoint triage snapshot

Join a capped process sample with TCP observations and selected service metadata.

How to use it

.\Get-SocEndpointSnapshot.ps1 -MaxRows 1000

Platform and permissions

Windows; CIM and NetTCPIP. Elevation may improve coverage.

What changes / what is read

Reads local metadata and returns an object; no report file is written automatically. Command-line output is opt-in.

Scope and interpretation

Separate queries are not atomic. PID reuse, protected data and row limits affect completeness. Returned errors and truncation fields must be reviewed.

Practice task

Run in a Windows lab; explain every collection error and compare the TCP process names with a fresh process lookup.

Reference

Microsoft documentation. Review the documentation for your installed version and use only an authorised learning or investigation environment.

This is personal educational material. Review the complete code and your signing policy before use. PowerShell code is displayed and downloaded as text; WordPress does not run it. Collection caps limit rows/files, not every provider’s wall-clock execution time.

PowerShell · PowerShell 5.1+ syntax target; Windows collectors require the stated Windows modules. Full Windows acceptance testing remains required.Download .ps1
#requires -Version 5.1
<# Read-only local snapshot. Output can contain sensitive endpoint information. #>
[CmdletBinding()]
param([ValidateRange(10,5000)][int]$MaxRows=1000,[switch]$IncludeCommandLine)
if ($env:OS -ne 'Windows_NT') { throw 'This collector requires Windows.' }
$issues=New-Object 'System.Collections.Generic.List[string]'
$truncated=New-Object 'System.Collections.Generic.List[string]'
$processes=@(); $connections=@(); $services=@()
try {
    $raw=@(Get-CimInstance Win32_Process -OperationTimeoutSec 15 -ErrorAction Stop | Select-Object -First ($MaxRows+1))
    if($raw.Count -gt $MaxRows){$truncated.Add('Processes')}
    $processes=@($raw | Select-Object -First $MaxRows | ForEach-Object {
        $row=[ordered]@{ProcessId=$_.ProcessId;ParentProcessId=$_.ParentProcessId;Name=$_.Name;ExecutablePath=$_.ExecutablePath;CreationDate=$_.CreationDate}
        if($IncludeCommandLine){$row.CommandLine=$_.CommandLine}
        [pscustomobject]$row
    })
} catch { $issues.Add('Processes: '+$_.Exception.Message) }
$names=@{};foreach($p in $processes){$names[[string]$p.ProcessId]=$p.Name}
try {
    $raw=@(Get-NetTCPConnection -ErrorAction Stop | Select-Object -First ($MaxRows+1))
    if($raw.Count -gt $MaxRows){$truncated.Add('TCP')}
    $connections=@($raw | Select-Object -First $MaxRows | ForEach-Object {
        [pscustomobject]@{LocalAddress=$_.LocalAddress;LocalPort=$_.LocalPort;RemoteAddress=$_.RemoteAddress;RemotePort=$_.RemotePort;State=[string]$_.State;ProcessId=$_.OwningProcess;ObservedProcessName=$names[[string]$_.OwningProcess]}
    })
} catch { $issues.Add('TCP: '+$_.Exception.Message) }
try {
    $raw=@(Get-CimInstance Win32_Service -OperationTimeoutSec 15 -ErrorAction Stop | Select-Object -First ($MaxRows+1))
    if($raw.Count -gt $MaxRows){$truncated.Add('Services')}
    $services=@($raw | Select-Object -First $MaxRows Name,State,StartMode,StartName,PathName)
} catch { $issues.Add('Services: '+$_.Exception.Message) }
[pscustomobject]@{CollectedUtc=[datetime]::UtcNow;Computer=$env:COMPUTERNAME;Processes=$processes;TCP=$connections;Services=$services;Truncated=$truncated.ToArray();Errors=$issues.ToArray();Note='Separate live queries are not an atomic forensic image; PID reuse and missing permissions can affect correlation.'}

Example code is displayed as text. Review it and test in your own lab before use.