accept non-boolean string values for the boolean $ZIP

append hostname to output file
This commit is contained in:
2026-09-30 07:20:37 -04:00
parent bb44f2a9ef
commit 745902f8c2
+28 -5
View File
@@ -7,16 +7,30 @@ Downloads and runs the DSA manifest collector.
Tools.ps1 must be dot-sourced by the caller first. Set $DSAManifestSource
in the caller's scope before using Run-Script -LivePSScript Get-DSAManifest.
The output path is generated in $Global:OutputDirectory with the filename
dsa-manifest-yyyyMMddHHmmss.csv, using the current local date and time.
Set the boolean $Zip to $true to include --zip; otherwise it is omitted.
dsa-manifest-HOSTNAME-yyyyMMddHHmmss.csv, using the computer name and current local date and time.
Set $Zip to 'true', '$true', 'yes', 'y', or '1' to include --zip.
Use 'false', '$false', 'no', 'n', or '0' to disable ZIP; an empty value also disables it.
Values are case-insensitive and surrounding whitespace is ignored.
#>
If ( [string]::IsNullOrWhiteSpace([string]$DSAManifestSource) ) {
Throw 'Set $DSAManifestSource in the caller before running Get-DSAManifest.'
}
# Normalize RMM text values without treating every nonempty string as true.
$DsaZipValue = ([string]$Zip).Trim().ToLowerInvariant()
If ( $DsaZipValue -in @('true', '$true', 'yes', 'y', '1') ) {
$DsaZipEnabled = $true
}
ElseIf ( $DsaZipValue -in @('', 'false', '$false', 'no', 'n', '0') ) {
$DsaZipEnabled = $false
}
Else {
Throw 'Invalid $Zip value. Use true, $true, yes, y, 1, false, $false, no, n, or 0.'
}
$DSAManifestOutput = Join-Path -Path $Global:OutputDirectory -ChildPath (
'dsa-manifest-{0}.csv' -f (Get-Date -Format 'yyyyMMddHHmmss')
'dsa-manifest-{0}-{1}.csv' -f $Env:COMPUTERNAME, (Get-Date -Format 'yyyyMMddHHmmss')
)
New-Item -Path $Global:OutputDirectory -ItemType Directory -Force -ErrorAction Stop | Out-Null
@@ -41,7 +55,7 @@ If ( [string]::IsNullOrWhiteSpace([string]$DsaDownloadedFile) -or
}
$DsaArguments = @('--source', [string]$DSAManifestSource, '--output', [string]$DSAManifestOutput)
If ( $Zip -eq $true ) {
If ( $DsaZipEnabled ) {
$DsaArguments += '--zip'
}
@@ -51,9 +65,18 @@ $DsaCommandLine = ($DsaArguments | ForEach-Object {
'"{0}"' -f ($_ -replace '(\\*)"', '$1$1\"' -replace '(\\+)$', '$1$1')
}) -join ' '
Write-Output 'Running dsa-collect.exe'
Write-Output "Running dsa-collect.exe (ZIP compression: ${DsaZipEnabled})"
$DsaProcess = Start-Process -FilePath $DsaExecutablePath -ArgumentList $DsaCommandLine `
-Wait -PassThru -WindowStyle Hidden -ErrorAction Stop
If ( $DsaProcess.ExitCode -ne 0 ) {
Throw "dsa-collect.exe failed with exit code $($DsaProcess.ExitCode)"
}
$DsaResultPath = $DSAManifestOutput
If ( $DsaZipEnabled ) {
$DsaResultPath = [System.IO.Path]::ChangeExtension($DSAManifestOutput, '.zip')
}
If ( !(Test-Path -LiteralPath $DsaResultPath -PathType Leaf) ) {
Throw "dsa-collect.exe did not create the expected output: ${DsaResultPath}"
}
Write-Output "DSA manifest created: ${DsaResultPath}"