ci(lint): enhance PSScriptAnalyzer settings and suppress false positives; improve error handling in scripts

This commit is contained in:
Simone
2026-05-13 19:06:50 +02:00
committed by Simone
parent 032d6f200e
commit 2ac26dbd00
11 changed files with 42 additions and 24 deletions
+2 -2
View File
@@ -329,7 +329,7 @@ function New-WinIsoNoPrompt {
$fsi.VolumeName = $label
$fsi.ChooseImageDefaultsForMediaType(13)
# 5+ GB ISO needs explicit large-volume defaults if available.
try { $fsi.UDFRevision = 0x102 } catch {}
try { $fsi.UDFRevision = 0x102 } catch { Write-Verbose "UDF revision not supported on this IMAPI version." }
Write-Host " Adding ISO tree (this takes a few minutes for 5+ GB)..." -ForegroundColor Yellow
$fsi.Root.AddTree($letter, $false)
@@ -1114,4 +1114,4 @@ Write-Host " .\Validate-DeployState.ps1 -VMIPAddress $guestIP"
Write-Host " .\Prepare-WinBuild2022.ps1 -VMIPAddress $guestIP [-SkipWindowsUpdate]"
Write-Host ""
Write-Host " VM is powered on with vmxnet3 + DHCP. Snapshot '$SnapshotName' taken." -ForegroundColor Green
+2 -2
View File
@@ -329,7 +329,7 @@ function New-WinIsoNoPrompt {
$fsi.VolumeName = $label
$fsi.ChooseImageDefaultsForMediaType(13)
# 5+ GB ISO needs explicit large-volume defaults if available.
try { $fsi.UDFRevision = 0x102 } catch {}
try { $fsi.UDFRevision = 0x102 } catch { Write-Verbose "UDF revision not supported on this IMAPI version." }
Write-Host " Adding ISO tree (this takes a few minutes for 5+ GB)..." -ForegroundColor Yellow
$fsi.Root.AddTree($letter, $false)
@@ -1114,4 +1114,4 @@ Write-Host " .\Validate-DeployState.ps1 -VMIPAddress $guestIP"
Write-Host " .\Prepare-WinBuild2025.ps1 -VMIPAddress $guestIP [-SkipWindowsUpdate]"
Write-Host ""
Write-Host " VM is powered on with vmxnet3 + DHCP. Snapshot '$SnapshotName' taken." -ForegroundColor Green
@@ -867,7 +867,6 @@ else {
$vsInstallerUrl = 'https://aka.ms/vs/stable/vs_buildtools.exe'
$vsInstallerPath = 'C:\CI\vs_BuildTools.exe'
$vsResultPath = 'C:\CI\vs_result.txt'
$vsLogPath = 'C:\CI\vs_log.txt'
Write-Host "Downloading VS Build Tools installer..."
Remove-Item $vsInstallerPath -ErrorAction SilentlyContinue # remove any stale/corrupt copy
@@ -867,7 +867,6 @@ else {
$vsInstallerUrl = 'https://aka.ms/vs/stable/vs_buildtools.exe'
$vsInstallerPath = 'C:\CI\vs_BuildTools.exe'
$vsResultPath = 'C:\CI\vs_result.txt'
$vsLogPath = 'C:\CI\vs_log.txt'
Write-Host "Downloading VS Build Tools installer..."
Remove-Item $vsInstallerPath -ErrorAction SilentlyContinue # remove any stale/corrupt copy
+3 -3
View File
@@ -438,7 +438,7 @@ try {
-Authentication Basic -ErrorAction Stop
Remove-PSSession $probe -ErrorAction SilentlyContinue
return $true
} catch { }
} catch { Write-Verbose "WinRM probe attempt failed." }
}
return $false
}
@@ -481,7 +481,7 @@ try {
if ($session) {
try {
Invoke-Command -Session $session -ScriptBlock { Restart-Computer -Force } -ErrorAction SilentlyContinue
} catch { }
} catch { Write-Verbose "Reboot command sent; session may have already dropped." }
Remove-PSSession $session -ErrorAction SilentlyContinue
}
@@ -597,7 +597,7 @@ try {
try {
Invoke-Command -Session $session -ScriptBlock { Restart-Computer -Force } -ErrorAction SilentlyContinue
}
catch { }
catch { Write-Verbose "Reboot command sent; session may have already dropped." }
Remove-PSSession $session -ErrorAction SilentlyContinue
$session = $null
+3 -3
View File
@@ -438,7 +438,7 @@ try {
-Authentication Basic -ErrorAction Stop
Remove-PSSession $probe -ErrorAction SilentlyContinue
return $true
} catch { }
} catch { Write-Verbose "WinRM probe attempt failed." }
}
return $false
}
@@ -481,7 +481,7 @@ try {
if ($session) {
try {
Invoke-Command -Session $session -ScriptBlock { Restart-Computer -Force } -ErrorAction SilentlyContinue
} catch { }
} catch { Write-Verbose "Reboot command sent; session may have already dropped." }
Remove-PSSession $session -ErrorAction SilentlyContinue
}
@@ -597,7 +597,7 @@ try {
try {
Invoke-Command -Session $session -ScriptBlock { Restart-Computer -Force } -ErrorAction SilentlyContinue
}
catch { }
catch { Write-Verbose "Reboot command sent; session may have already dropped." }
Remove-PSSession $session -ErrorAction SilentlyContinue
$session = $null
+2 -2
View File
@@ -37,6 +37,8 @@
.EXAMPLE
.\Validate-SetupState.ps1 -VMIPAddress 192.168.79.129 -Remediate
#>
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '',
Justification = 'Template setup script: plain-text password required to bootstrap WinRM credential chain before Credential Manager is available.')]
[CmdletBinding()]
param(
[Parameter(Mandatory)] [string] $VMIPAddress,
@@ -273,8 +275,6 @@ try {
Write-Host ''
$failed = 0
$deployCnt = 0
$setupCnt = 0
$inSetup = $false
foreach ($r in $checks) {