Fix Windows task and certificate collector reliability
This commit is contained in:
@@ -1,12 +1,17 @@
|
||||
#requires -Version 5.1
|
||||
[CmdletBinding()]
|
||||
param([ValidateSet('all','system','roles','services','network','tasks','software','storage','shares','certificates')][string]$Section = 'all')
|
||||
param([ValidateSet('all','system','roles','services','network','tasks','software','storage','shares','certificates')][string]$Section = 'all', [switch]$Diagnostic)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$ProgressPreference = 'SilentlyContinue'
|
||||
$WarningPreference = 'SilentlyContinue'
|
||||
$InformationPreference = 'SilentlyContinue'
|
||||
$env:PSModulePath = Join-Path $PSHOME 'Modules'
|
||||
if ($PSVersionTable.PSEdition -eq 'Core') {
|
||||
# Inbox Windows modules remain under WindowsPowerShell when invoked from PS7.
|
||||
$env:PSModulePath += ';' + (Join-Path ([Environment]::SystemDirectory) 'WindowsPowerShell\v1.0\Modules')
|
||||
}
|
||||
$script:SamsaraDiagnostic = $Diagnostic.IsPresent
|
||||
[Console]::OutputEncoding = New-Object System.Text.UTF8Encoding($false)
|
||||
if ([Environment]::OSVersion.Platform -ne [PlatformID]::Win32NT) {
|
||||
[Console]::Error.WriteLine('This collector requires a local Windows Server execution host.')
|
||||
@@ -30,7 +35,7 @@ $collectors = [ordered]@{
|
||||
}
|
||||
if ($Section -ne 'all') {
|
||||
$result = Invoke-SamsaraSection $Section $collectors[$Section]
|
||||
ConvertTo-Json -InputObject $result -Depth 12 -Compress
|
||||
ConvertTo-SamsaraJson $result 12
|
||||
exit 0
|
||||
}
|
||||
# Direct PowerShell use emits the same complete inventory envelope as the Python backend.
|
||||
@@ -50,7 +55,7 @@ foreach ($name in $collectors.Keys) {
|
||||
} elseif ($name -eq 'shares') { $inventory.storage += @($result.data) }
|
||||
else { $inventory[$name] = @($result.data) }
|
||||
}
|
||||
ConvertTo-Json -InputObject ([ordered]@{ schema_version='1.0'; synthetic=$false; collected_at=$collectedAt
|
||||
server=$server; checks=$checks; inventory=$inventory }) -Depth 14 -Compress
|
||||
ConvertTo-SamsaraJson ([ordered]@{ schema_version='1.0'; synthetic=$false; collected_at=$collectedAt
|
||||
server=$server; checks=$checks; inventory=$inventory }) 14
|
||||
|
||||
exit 0
|
||||
|
||||
Reference in New Issue
Block a user