Skip to content

Commit

Permalink
Update PowerShell_Docker_Containers.mkape
Browse files Browse the repository at this point in the history
Condensed code.
  • Loading branch information
DReneau authored Oct 19, 2024
1 parent aa3729f commit 39f6b75
Showing 1 changed file with 4 additions and 27 deletions.
31 changes: 4 additions & 27 deletions Modules/Windows/PowerShell_Docker_Containers.mkape
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,21 @@ Description: Docker Container Details
Category: LiveResponse
Author: DReneau
Version: 1.0
Id: 67e875ee-1cb2-4b06-ab94-83540f8f2482
Id: 87bf8201-6256-45ad-8b2b-a6034235db53
ExportFormat: txt
Processors:
- Executable: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
CommandLine: |
$maxRetries = 3;
$retryCount = 0;
$filePath = '%destinationDirectory%\docker_container_info.txt';

$dockerInfo = (docker version) | Out-String;
$dockerPS = (docker ps --all --format 'ID: {{.ID}} | Name: {{.Names}} | Image: {{.Image}} | Size: {{.Size}} | Status: {{.Status}} | Command: {{.Command}} | Ports: {{.Ports}}') | Out-String;
$dockerOutput = (docker version | Out-String).TrimEnd() + [System.Environment]::NewLine + [System.Environment]::NewLine +
(docker ps --all --format 'ID: {{.ID}} | Name: {{.Names}} | Image: {{.Image}} | Size: {{.Size}} | Status: {{.Status}} | Command: {{.Command}}' | Out-String).TrimEnd();

$separator = [System.Environment]::NewLine + [System.Environment]::NewLine;

$output = $dockerInfo + $separator + $dockerPS;

$dockerOutput = $dockerInfo.TrimEnd() + $separator + $dockerPS.TrimEnd();

while ($retryCount -lt $maxRetries) {
try {
Set-Content -Path $filePath -Value $dockerOutput -Encoding UTF8 -Force;
Write-Host 'Docker details have been successfully written to: ' $filePath -ForegroundColor Green;
break;
} catch {
Write-Host "Attempt $retryCount failed to write to the file. Retrying..." -ForegroundColor Yellow;
Start-Sleep -Seconds 2;
$retryCount++;
}
}

if ($retryCount -eq $maxRetries) {
Write-Host 'Failed to write Docker details after multiple attempts.' -ForegroundColor Red;
}
Set-Content -Path $filePath -Value $dockerOutput -Encoding UTF8;
ExportFormat: txt

# Documentation
# https://docs.docker.com/reference/cli/docker/container/ls/
# This module combines Docker ps and Docker version commands. Output is based on installed Docker and the status.
#
# Example:
# .\kape.exe --msource C:\kape\path\to\acquired\Windows\System32\config --mdest C:\kape\out --module powershell_docker_containers

0 comments on commit 39f6b75

Please sign in to comment.