test(lab): make the controller's setup and removal robust on dirty machines
The operating-system matrix runs on Windows Server 2019, 2022 and 2025 found
three defects in the fixture setup and removal of Invoke-NTFSSecurityLabTest.ps1:
- A native command's stderr that is redirected with 2>&1 is a terminating
error in Windows PowerShell 5.1 under $ErrorActionPreference = 'Stop'. The
first "The directory is not empty" line from PowerShell 7 ended the removal
on Server 2019 before any retry. The removal is now a bounded loop whose
PowerShell 7 command writes its errors to its output.
- Get-LocalGroupMember fails with "Failed to compare two elements in the
array" when a group holds an orphaned SID, for example that of an account an
earlier run deleted. The setup adds the members with Add-LocalGroupMember and
ignores MemberExistsException instead of checking the members first.
- A user profile that is gone in the meantime no longer fails the client
cleanup, and the retries are reported to the host.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: AI Assistant <ai@example.com>
$accountSids=@(Invoke-LabCommand-ComputerName$DomainController-ActivityName'Read the accounts'-ScriptBlock$accountSidScript-ArgumentList$organizationalUnitName@labCommand)
$null=Invoke-LabCommand-ComputerName$FileServer-ActivityName'Remove the share and the folders'-ScriptBlock$removeFileServerScript-ArgumentList$shareName,$shareLocalPath,$payloadPath,$localGroupName,$accountSids@labCommand
$removed=Invoke-LabCommand-ComputerName$FileServer-ActivityName'Remove the share and the folders'-ScriptBlock$removeFileServerScript-ArgumentList$shareName,$shareLocalPath,$payloadPath,$localGroupName,$accountSids@labCommand
foreach($messagein@($removed)){
Write-LabProgress"${FileServer}: $message"
}
$null=Invoke-LabCommand-ComputerName$Client-ActivityName'Remove the members and the folder'-ScriptBlock$removeClientScript-ArgumentList$payloadPath,$accountSids@labCommand
$null=Invoke-LabCommand-ComputerName$DomainController-ActivityName'Remove the accounts'-ScriptBlock$removeAccountScript-ArgumentList$organizationalUnitName@labCommand