Test-ActivityLog
Validates that the activity log is reachable and writable. Can optionally archive a bad file and recreate it.
Syntax
Test-ActivityLog [-LogLocation <String>] [-LogFileName <String>] [-TryFix]
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
LogLocation | string | inferred | Optional directory for logs. Resolved the same way as Write-Log and created if missing. |
LogFileName | string | activity.log | File name to check. |
TryFix | switch | off | If the file is unwritable, archive it and attempt to create a fresh one, then retry logging. |
Return value
Returns a [pscustomobject] with:
Status:OKorKOPath: full path to the checked log fileFixed:$truewhenTryFixsuccessfully repaired the file, otherwise$falseor$nullError: present only whenStatusisKO
Behavior
- Resolves the log directory (creates it when needed).
- Verifies the target file exists. If missing, it returns
KOand emits an error. - Writes a test log entry through
Write-Log. - On failure and with
-TryFix, archives the existing file as<name>.unwritable.<yyyyMMdd-HHmmss>.bak, then retries the write. - Reports success (
OK) or failure (KO) with details.
Examples
Check that the default activity log is writable:
Test-ActivityLog -LogLocation "C:\Logs"
Attempt an automatic repair when the file is locked or corrupted:
Test-ActivityLog -LogLocation "C:\Logs" -TryFix
Questions and answers
Does Test-ActivityLog create the file?
It creates the directory if missing. The file must exist; otherwise it returns KO with NotFound. If the file exists but is unwritable, use -TryFix to archive it and recreate a new one.