Skip to content

Commit

Permalink
computer rename retries
Browse files Browse the repository at this point in the history
  • Loading branch information
clr2of8 committed Apr 2, 2024
1 parent 1e70f7b commit 2c6fb69
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
33 changes: 12 additions & 21 deletions Public/Invoke-AtomicRunner.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function Invoke-AtomicRunner {

[Parameter(Mandatory = $false)]
[switch]
$anyOS=$false,
$anyOS = $false,

[parameter(Mandatory = $false)]
[ValidateRange(0, [int]::MaxValue)]
Expand Down Expand Up @@ -115,31 +115,22 @@ function Invoke-AtomicRunner {
else {
if ($debug) { LogRunnerMsg "Debug: pretending to rename the computer to $newHostName"; exit }
if (-not $shouldRename) { Restart-Computer -Force }
if ($artConfig.gmsaAccount) {
$retry = $true; $count = 0
while ($retry) {
# add retry loop to avoid this occassional error "The verification of the MSA failed with error 1355"
Invoke-Command -ComputerName '127.0.0.1' -ConfigurationName 'RenameRunnerEndpoint' -ScriptBlock { Rename-Computer -NewName $Using:newHostName -Force -Restart }
Start-Sleep 120; $count = $count + 1
LogRunnerMsg "Retrying computer rename $count"
if ($count -gt 15) { $retry = $false }
}
}
else {
try {
Rename-Computer -NewName $newHostName -Force -Restart -ErrorAction stop
}
catch {
if ($artConfig.verbose) { LogRunnerMsg $_ }
}
$retry = $true; $count = 0
while ($retry) {
Rename-Computer -NewName $newHostName -Force -Restart
Start-Sleep 120; $count = $count + 1
LogRunnerMsg "Retrying computer rename $count"
if ($count -gt 60) { $retry = $false }
}

Start-Sleep -seconds 30
LogRunnerMsg "uh oh, still haven't restarted - should never get to here"
$retry = $true; $count = 0
while ($retry) {
Restart-Computer -Force
Start-Sleep 300; $count = $count + 1
$count = $count + 1
LogRunnerMsg "Rename retry $count"
Restart-Computer -Force
Start-Sleep 300;
if ($count -gt 60) { $retry = $false }
}
exit
Expand Down Expand Up @@ -227,7 +218,7 @@ function Invoke-AtomicRunner {
if ($scheduledTaskCleanup) {
# Cleanup after running test
Write-Host -Fore cyan "Sleeping for $SleepTillCleanup seconds before cleaning up for $($tr.Technique) $($tr.auto_generated_guid) "; Start-Sleep -Seconds $SleepTillCleanup
$htvars.Add("Cleanup",$true)
$htvars.Add("Cleanup", $true)
Invoke-AtomicTestFromScheduleRow $tr
}
else {
Expand Down
3 changes: 0 additions & 3 deletions Public/config.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ $artConfig = [PSCustomObject]@{
kickOffDelay = New-TimeSpan -Minutes 0 # an additional delay before Invoke-KickoffAtomicRunner calls Invoke-AtomicRunner
scheduleFileName = "AtomicRunnerSchedule.csv"

# [optional] If you need to use a group managed service account in order to rename the computer, enter it here
gmsaAccount = $null

# [optional] Logging Module, uses Syslog-ExecutionLogger if left blank and the syslogServer and syslogPort are set, otherwise it uses the Default-ExecutionLogger
LoggingModule = ''

Expand Down

0 comments on commit 2c6fb69

Please sign in to comment.