updates
This commit is contained in:
@@ -29,8 +29,15 @@ $drives | Format-Table User, Drive, RemotePath, Source -AutoSize -Wrap
|
|||||||
.\Get-AllNetworkDrives.ps1 | Export-Csv .\NetworkDrives.csv -NoTypeInformation -Encoding UTF8
|
.\Get-AllNetworkDrives.ps1 | Export-Csv .\NetworkDrives.csv -NoTypeInformation -Encoding UTF8
|
||||||
#>
|
#>
|
||||||
|
|
||||||
[CmdletBinding()]
|
[CmdletBinding(PositionalBinding=$false)]
|
||||||
param(
|
param(
|
||||||
|
# Run-Script passes an empty positional argument even when none was supplied.
|
||||||
|
# Absorb only blank input here so it cannot bind to the SavedOnly switch.
|
||||||
|
[Parameter(Position=0,DontShow=$true)]
|
||||||
|
[AllowEmptyString()]
|
||||||
|
[ValidatePattern('^\s*$')]
|
||||||
|
[string]$RmmArgument,
|
||||||
|
|
||||||
[switch]$SavedOnly
|
[switch]$SavedOnly
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -367,11 +367,19 @@ function Save-OfficeDownload {
|
|||||||
$null = Write-Output "Download attempt ${attempt}: $Uri -> $Path"
|
$null = Write-Output "Download attempt ${attempt}: $Uri -> $Path"
|
||||||
Invoke-WebRequest -UseBasicParsing -Uri $Uri -OutFile $Path -TimeoutSec $TimeoutSeconds -ErrorAction Stop
|
Invoke-WebRequest -UseBasicParsing -Uri $Uri -OutFile $Path -TimeoutSec $TimeoutSeconds -ErrorAction Stop
|
||||||
if ((Get-Item -LiteralPath $Path -ErrorAction Stop).Length -eq 0) { throw 'Download was empty.' }
|
if ((Get-Item -LiteralPath $Path -ErrorAction Stop).Length -eq 0) { throw 'Download was empty.' }
|
||||||
|
if ($attempt -gt 1) { $null = Write-Output "Download recovered on attempt ${attempt}: $Uri -> $Path" }
|
||||||
return
|
return
|
||||||
} catch {
|
} catch {
|
||||||
Write-Error "Download attempt $attempt failed: $($_.Exception.Message)" -ErrorAction Continue
|
$reason = $_.Exception.Message
|
||||||
if ($attempt -eq $definitions.DownloadAttempts) { throw }
|
if ($attempt -eq $definitions.DownloadAttempts) {
|
||||||
Start-Sleep -Seconds ($definitions.DownloadRetrySeconds * $attempt)
|
# The entry point logs and reports the terminal error once to Syncro.
|
||||||
|
throw "Download failed after $attempt attempts: $Uri -> $Path. $reason"
|
||||||
|
}
|
||||||
|
$delay = $definitions.DownloadRetrySeconds * $attempt
|
||||||
|
# Tools.ps1 logs Write-Output; suppress its echo so a recoverable attempt
|
||||||
|
# neither pollutes return values nor produces an error in Syncro.
|
||||||
|
$null = Write-Output "Download attempt $attempt of $($definitions.DownloadAttempts) failed for $Uri -> $Path. $reason Retrying in $delay seconds."
|
||||||
|
Start-Sleep -Seconds $delay
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,4 +68,5 @@ powershell.exe -NoProfile -File .\tests\Upload-File.Tests.ps1
|
|||||||
powershell.exe -NoProfile -File .\tests\Get-DSAManifest.Tests.ps1
|
powershell.exe -NoProfile -File .\tests\Get-DSAManifest.Tests.ps1
|
||||||
powershell.exe -NoProfile -File .\tests\Download-File.Tests.ps1
|
powershell.exe -NoProfile -File .\tests\Download-File.Tests.ps1
|
||||||
powershell.exe -NoProfile -File .\tests\ConvertTo-RmmBoolean.Tests.ps1
|
powershell.exe -NoProfile -File .\tests\ConvertTo-RmmBoolean.Tests.ps1
|
||||||
|
powershell.exe -NoProfile -File .\tests\Get-AllNetworkDrives.Tests.ps1
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ The former Get Help 30-minute background-wait cutoff has been removed with the s
|
|||||||
|
|
||||||
Transient failures get bounded recovery before deployment stops:
|
Transient failures get bounded recovery before deployment stops:
|
||||||
|
|
||||||
- HTTP downloads, including the ODT discovery page, get three attempts. ODT `/download` also gets three attempts using the same staging folder, before any app removal. An unrecognized discovery page, invalid signature, or invalid staged payload still fails validation.
|
- HTTP downloads, including the ODT discovery page, get three attempts. Recoverable failures and successful retries are recorded in the Tools diagnostic log with the URL and destination, without emitting errors to Syncro. If all attempts fail, the final error identifies the URL, destination, attempt count, and last failure. ODT `/download` also gets three attempts using the same staging folder, before any app removal. An unrecognized discovery page, invalid signature, or invalid staged payload still fails validation.
|
||||||
- Direct machine and per-user companion MSI removal retry Windows Installer's [busy result, `1618`](https://learn.microsoft.com/en-us/windows/win32/msi/error-codes), up to five attempts with 15 seconds between attempts. Other installer failure codes retain their existing handling. This retry applies to `msiexec.exe`, not ODT's internal `RemoveMSI` operation. The script does not kill an unrelated installer or blindly repeat an Office removal or installation.
|
- Direct machine and per-user companion MSI removal retry Windows Installer's [busy result, `1618`](https://learn.microsoft.com/en-us/windows/win32/msi/error-codes), up to five attempts with 15 seconds between attempts. Other installer failure codes retain their existing handling. This retry applies to `msiexec.exe`, not ODT's internal `RemoveMSI` operation. The script does not kill an unrelated installer or blindly repeat an Office removal or installation.
|
||||||
- After successful operations, machine removal and installation verification allow up to five minutes of polling for registry/package state to settle. The standalone user's Teams add-in verification retains its 60-second allowance. Reads that fail still raise an error; inaccessible state is not treated as proof that an app is gone.
|
- After successful operations, machine removal and installation verification allow up to five minutes of polling for registry/package state to settle. The standalone user's Teams add-in verification retains its 60-second allowance. Reads that fail still raise an error; inaccessible state is not treated as proof that an app is gone.
|
||||||
- Appx removal checks whether the exact package disappeared even when the removal command reports an error. If it remains, removal retries up to three times, each followed by the verification wait. Installed and provisioned packages must both be absent before continuing.
|
- Appx removal checks whether the exact package disappeared even when the removal command reports an error. If it remains, removal retries up to three times, each followed by the verification wait. Installed and provisioned packages must both be absent before continuing.
|
||||||
|
|||||||
@@ -0,0 +1,105 @@
|
|||||||
|
#Requires -Version 5.1
|
||||||
|
# Offline binding tests: keep the real parameter declaration and shim, replace
|
||||||
|
# the inventory body with a probe, and mock downloads. No registry/COM operations.
|
||||||
|
$ErrorActionPreference = 'Stop'
|
||||||
|
$DriveTestRepo = Split-Path $PSScriptRoot -Parent
|
||||||
|
$DriveTestTokens = $null
|
||||||
|
$DriveTestErrors = $null
|
||||||
|
$DriveTestToolsAst = [Management.Automation.Language.Parser]::ParseFile(
|
||||||
|
(Join-Path $DriveTestRepo 'Tools.ps1'), [ref]$DriveTestTokens, [ref]$DriveTestErrors)
|
||||||
|
If ($DriveTestErrors.Count) { Throw ($DriveTestErrors | Out-String) }
|
||||||
|
$DriveTestRunDefinition = $DriveTestToolsAst.Find({
|
||||||
|
param($Node)
|
||||||
|
$Node -is [Management.Automation.Language.FunctionDefinitionAst] -and $Node.Name -eq 'Run-Script'
|
||||||
|
}, $true)
|
||||||
|
If (!$DriveTestRunDefinition) { Throw 'Missing helper: Run-Script' }
|
||||||
|
. ([scriptblock]::Create($DriveTestRunDefinition.Extent.Text))
|
||||||
|
|
||||||
|
$DriveTestInventoryAst = [Management.Automation.Language.Parser]::ParseFile(
|
||||||
|
(Join-Path $DriveTestRepo 'Get-AllNetworkDrives.ps1'), [ref]$DriveTestTokens, [ref]$DriveTestErrors)
|
||||||
|
If ($DriveTestErrors.Count) { Throw ($DriveTestErrors | Out-String) }
|
||||||
|
$DriveTestProbeSource = $DriveTestInventoryAst.ParamBlock.Extent.Text + [Environment]::NewLine + @'
|
||||||
|
[pscustomobject]@{
|
||||||
|
Probe = 'NetworkDrives'
|
||||||
|
SavedOnly = $SavedOnly.IsPresent
|
||||||
|
CallerValue = $DriveTestCallerValue
|
||||||
|
}
|
||||||
|
'@
|
||||||
|
$DriveTestProbe = [scriptblock]::Create($DriveTestProbeSource)
|
||||||
|
|
||||||
|
Function IsURLValid { Return $true }
|
||||||
|
Function Download-File { Throw 'This fix must retain the existing Run-Script download path.' }
|
||||||
|
Function New-Object {
|
||||||
|
param([string]$TypeName)
|
||||||
|
If ($TypeName -ne 'Net.WebClient') { Throw "Unexpected object in test: $TypeName" }
|
||||||
|
$Client = [pscustomobject]@{}
|
||||||
|
$Client | Add-Member -MemberType ScriptMethod -Name DownloadString -Value {
|
||||||
|
param($URL)
|
||||||
|
$script:DriveTestWebDownloads++
|
||||||
|
Switch ($URL) {
|
||||||
|
'https://dev.emberkom.com/emberkom/management-scripts/raw/branch/master/Tools.ps1' {
|
||||||
|
Return $script:DriveTestRunDefinition.Extent.Text
|
||||||
|
}
|
||||||
|
'https://dev.emberkom.com/emberkom/management-scripts/raw/branch/master/Get-AllNetworkDrives.ps1' {
|
||||||
|
Return $script:DriveTestProbeSource
|
||||||
|
}
|
||||||
|
default { Throw "Unexpected URL in test: $URL" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Return $Client
|
||||||
|
}
|
||||||
|
|
||||||
|
Function Test-DriveRmmBinding {
|
||||||
|
param([string]$Name, [hashtable]$Parameters, [switch]$UseShim)
|
||||||
|
$script:DriveTestWebDownloads = 0
|
||||||
|
$DriveTestCallerValue = 'Caller value with spaces & symbols'
|
||||||
|
$Output = @(If ($UseShim) {
|
||||||
|
. (Join-Path $DriveTestRepo 'rmm\Get-AllNetworkDrives.ps1')
|
||||||
|
} Else {
|
||||||
|
Run-Script -LivePSScript Get-AllNetworkDrives @Parameters
|
||||||
|
})
|
||||||
|
$Probe = @($Output | Where-Object { $_.PSObject.Properties['Probe'] })
|
||||||
|
If ($Probe.Count -ne 1 -or $Probe[0].SavedOnly -ne $false -or
|
||||||
|
$Probe[0].CallerValue -cne $DriveTestCallerValue) {
|
||||||
|
Throw "${Name}: must run with SavedOnly false and retain access to caller variables."
|
||||||
|
}
|
||||||
|
$ExpectedDownloads = If ($UseShim) { 2 } Else { 1 }
|
||||||
|
If ($script:DriveTestWebDownloads -ne $ExpectedDownloads) { Throw "${Name}: unexpected download path." }
|
||||||
|
Write-Host "PASS: ${Name}: empty argument tolerated, caller variables visible, existing download path retained."
|
||||||
|
}
|
||||||
|
|
||||||
|
Test-DriveRmmBinding -Name 'Omitted Arguments' -Parameters @{}
|
||||||
|
Test-DriveRmmBinding -Name 'Null Arguments' -Parameters @{Arguments=$null}
|
||||||
|
Test-DriveRmmBinding -Name 'Empty Arguments' -Parameters @{Arguments=''}
|
||||||
|
Test-DriveRmmBinding -Name 'Legacy null sentinel' -Parameters @{Arguments='null'}
|
||||||
|
Test-DriveRmmBinding -Name 'Whitespace Arguments' -Parameters @{Arguments=" `t`r`n "}
|
||||||
|
Test-DriveRmmBinding -Name 'Real Syncro shim' -UseShim
|
||||||
|
|
||||||
|
$DriveTestCallerValue = 'Direct caller'
|
||||||
|
Foreach ($Case in @(
|
||||||
|
@{Name='No parameters'; Parameters=@{}; Expected=$false}
|
||||||
|
@{Name='SavedOnly true'; Parameters=@{SavedOnly=$true}; Expected=$true}
|
||||||
|
@{Name='SavedOnly false'; Parameters=@{SavedOnly=$false}; Expected=$false}
|
||||||
|
)) {
|
||||||
|
$Parameters = $Case.Parameters
|
||||||
|
$Probe = @(& $DriveTestProbe @Parameters)
|
||||||
|
If ($Probe.Count -ne 1 -or $Probe[0].SavedOnly -ne $Case.Expected) { Throw "Direct invocation failed: $($Case.Name)" }
|
||||||
|
}
|
||||||
|
$Probe = & $DriveTestProbe -SavedOnly
|
||||||
|
If ($Probe.SavedOnly -ne $true) { Throw 'The bare -SavedOnly switch must still enable saved-only inventory.' }
|
||||||
|
& {
|
||||||
|
$Probe = . $DriveTestProbe -SavedOnly:$false
|
||||||
|
If ($Probe.SavedOnly -ne $false -or $Probe.CallerValue -cne $DriveTestCallerValue) {
|
||||||
|
Throw 'Dot-sourced invocation must preserve switch behavior and caller-variable access.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Write-Host 'PASS: direct and dot-sourced invocations preserve optional SavedOnly behavior.'
|
||||||
|
|
||||||
|
Foreach ($UnexpectedArgument in @('false', 'true', '-SavedOnly', 'unexpected')) {
|
||||||
|
$Caught = $null
|
||||||
|
Try { Invoke-Command -ScriptBlock $DriveTestProbe -ArgumentList $UnexpectedArgument | Out-Null }
|
||||||
|
Catch { $Caught = $_ }
|
||||||
|
If ($null -eq $Caught) { Throw "Unexpected positional input was silently accepted: $UnexpectedArgument" }
|
||||||
|
}
|
||||||
|
Write-Host 'PASS: nonblank positional input is rejected instead of silently ignored.'
|
||||||
|
Write-Host "All Get-AllNetworkDrives binding tests passed on PowerShell $($PSVersionTable.PSVersion), $([IntPtr]::Size * 8)-bit."
|
||||||
@@ -77,10 +77,13 @@ try {
|
|||||||
[IO.File]::WriteAllText($OutFile, 'downloaded fixture')
|
[IO.File]::WriteAllText($OutFile, 'downloaded fixture')
|
||||||
}
|
}
|
||||||
$script:downloadCalls=0; $script:downloadRecovers=$true
|
$script:downloadCalls=0; $script:downloadRecovers=$true
|
||||||
Save-OfficeDownload 'https://fixture.invalid/' (Join-Path $testRoot 'download') 2>$null
|
$output = @(Save-OfficeDownload 'https://fixture.invalid/' (Join-Path $testRoot 'download') 2>&1)
|
||||||
Assert-OfficeTest ($script:downloadCalls -eq 2 -and (Get-Content -LiteralPath (Join-Path $testRoot 'download') -Raw) -eq 'downloaded fixture') 'A transient download error should recover.'
|
Assert-OfficeTest ($script:downloadCalls -eq 2 -and (Get-Content -LiteralPath (Join-Path $testRoot 'download') -Raw) -eq 'downloaded fixture') 'A transient download error should recover.'
|
||||||
|
Assert-OfficeTest ($output.Count -eq 0) 'A recovered download must not emit success-stream diagnostics or Syncro errors.'
|
||||||
|
$log = Get-Content -LiteralPath $Global:LogFile -Raw
|
||||||
|
Assert-OfficeTest ($log -match 'Download attempt 1 of 3 failed for https://fixture.invalid/' -and $log -match 'Temporary network failure Retrying in 3 seconds' -and $log -match 'Download recovered on attempt 2: https://fixture.invalid/') 'Retry details and recovery must remain in the Tools diagnostic log.'
|
||||||
$script:downloadCalls=0; $script:downloadRecovers=$false
|
$script:downloadCalls=0; $script:downloadRecovers=$false
|
||||||
Assert-OfficeThrows { Save-OfficeDownload 'https://fixture.invalid/' (Join-Path $testRoot 'download') 2>$null } 'Temporary network failure'
|
Assert-OfficeThrows { Save-OfficeDownload 'https://fixture.invalid/' (Join-Path $testRoot 'download') } 'Download failed after 3 attempts: https://fixture.invalid/.*Temporary network failure'
|
||||||
Assert-OfficeTest ($script:downloadCalls -eq (Get-OfficeDeploymentDefinitions).DownloadAttempts) 'Persistent download failure must remain bounded.'
|
Assert-OfficeTest ($script:downloadCalls -eq (Get-OfficeDeploymentDefinitions).DownloadAttempts) 'Persistent download failure must remain bounded.'
|
||||||
}
|
}
|
||||||
& {
|
& {
|
||||||
|
|||||||
Reference in New Issue
Block a user