diff --git a/projects/msp-tools/msp-audit-scripts/workstation_audit.ps1 b/projects/msp-tools/msp-audit-scripts/workstation_audit.ps1 index fbcaa03..1bfa404 100644 --- a/projects/msp-tools/msp-audit-scripts/workstation_audit.ps1 +++ b/projects/msp-tools/msp-audit-scripts/workstation_audit.ps1 @@ -15,7 +15,7 @@ # never rename without bumping Schema Version. # ============================================================ -$ScriptVersion = "2.0.1" +$ScriptVersion = "2.0.2" $ScriptSchemaVersion = "2.0" $ScriptBuildDate = "2026-04-17" @@ -1969,11 +1969,12 @@ try { $net.EstablishedOutbound = $established } catch { $net.EstablishedOutboundError = $_.Exception.Message; $net.EstablishedOutbound = @() } - # HOSTS file + # HOSTS file (read via .NET to avoid PSObject metadata baggage in Get-Content output; + # Get-Content lines carry PSDrive/Provider reflection refs that ConvertTo-Json explodes into 40+ MB) try { $hostsPath = "$env:windir\System32\drivers\etc\hosts" - $hostsContent = Get-Content $hostsPath -ErrorAction SilentlyContinue - $hostsActive = @($hostsContent | Where-Object { $_ -and ($_ -notmatch '^\s*#') -and ($_.Trim() -ne '') }) + $hostsLines = if (Test-Path $hostsPath) { [System.IO.File]::ReadAllLines($hostsPath) } else { @() } + $hostsActive = @($hostsLines | Where-Object { $_ -and ($_ -notmatch '^\s*#') -and ($_.Trim() -ne '') } | ForEach-Object { [string]$_ }) $net.HostsFile = [ordered]@{ ActiveEntryCount = $hostsActive.Count ActiveEntries = $hostsActive