Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'AzureBasicLoadBalancerUpgrade'

# Version number of this module.
ModuleVersion = '2.5.39'
ModuleVersion = '2.5.40'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down Expand Up @@ -107,7 +107,7 @@
# IconUri = ''

# ReleaseNotes of this module
ReleaseNotes = 'Improve NAT Rule migration logging and error handling.'
ReleaseNotes = 'Simplify NAT Rule migration.'

# Prerelease string of this module
# Prerelease = 'beta'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function log {
$terminateOnError
)

$timestamp = Get-Date -Format 'yyyy-MM-ddTHH:mm:sszz'
$timestamp = Get-Date -Format 'yyyy-MM-ddTHH:mm:ss.ffzz'
Add-Content -Path ("Start-AzBasicLoadBalancerUpgrade.log") -Value ($timestamp + " " + "[$Severity] - " + $Message) -Force
$outputMessage = "{0} [{1}]:{2}" -f $timestamp, $Severity,($Message -replace '\s\s+?','')
If ($global:FollowLog) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,24 +152,14 @@ function NatRulesMigration {
return
}
else {
log -Message "[NatRulesMigration] $($StdLoadBalancer.InboundNatRules.Count) NAT Rules migrated. Saving Standard Load Balancer '$($StdLoadBalancer.Name)'..."
log -Message "[NatRulesMigration] $($StdLoadBalancer.InboundNatRules.Count) NAT Rules applied to LB config. Saving Standard Load Balancer '$($StdLoadBalancer.Name)'..."

try {
$ErrorActionPreference = 'Stop'

$UpdateLBNATRulesJob = Set-AzLoadBalancer -LoadBalancer $StdLoadBalancer -AsJob

While ($UpdateLBNATRulesJob.State -eq 'Running') {
Start-Sleep -Seconds 15
log -Message "[NatRulesMigration] Waiting for saving standard load balancer $($StdLoadBalancer.Name) job to complete..."
}

If ($UpdateLBNATRulesJob.Error -or $UpdateLBNATRulesJob.State -eq 'Failed') {
log -Severity Error -Message "Saving Standard Load Balancer $($StdLoadBalancer.Name) failed with the following errors: $($UpdateLBNATRulesJob.error; $UpdateLBNATRulesJob | Receive-Job). Migration will continue--to recover, manually add the NAT rules to the load balancer, then correct NAT Rule NIC membership after the script completes."
}
Set-AzLoadBalancer -LoadBalancer $StdLoadBalancer > $null
Copy link

Copilot AI Aug 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the asynchronous job handling eliminates progress feedback and detailed error information that was previously available. The original implementation provided status updates during long-running operations and captured specific job errors, which could be valuable for troubleshooting.

Suggested change
Set-AzLoadBalancer -LoadBalancer $StdLoadBalancer > $null
$job = Set-AzLoadBalancer -LoadBalancer $StdLoadBalancer -AsJob
log -Message "[NatRulesMigration] Set-AzLoadBalancer job started (Id: $($job.Id)). Monitoring progress..."
while ($job.State -eq 'Running' -or $job.State -eq 'NotStarted') {
log -Message "[NatRulesMigration] Set-AzLoadBalancer job status: $($job.State)..."
Start-Sleep -Seconds 5
$job = Get-Job -Id $job.Id
}
if ($job.State -eq 'Completed') {
log -Message "[NatRulesMigration] Set-AzLoadBalancer job completed successfully."
# Optionally, retrieve job output if needed
# $output = Receive-Job -Id $job.Id
}
elseif ($job.State -eq 'Failed') {
$errorMsg = "[NatRulesMigration] Set-AzLoadBalancer job failed. Error: $((Receive-Job -Id $job.Id | Out-String))"
log "Error" $errorMsg
}
else {
$errorMsg = "[NatRulesMigration] Set-AzLoadBalancer job ended with unexpected state: $($job.State)."
log "Error" $errorMsg
}
# Clean up job
Remove-Job -Id $job.Id

Copilot uses AI. Check for mistakes.
}
catch {
$message = "[NatRulesMigration] Failed to update new standard load balancer '$($stdLoadBalancer.Name)' in resource group '$($StdLoadBalancer.ResourceGroupName)' after attempting to add migrated inbound NAT rule configurations. Migration will continue, INBOUND NAT RULES WILL NEED TO BE MANUALLY ADDED to the load balancer. Error: $_"
$message = "[NatRulesMigration] Failed to update new standard load balancer '$($stdLoadBalancer.Name)' in resource group '$($StdLoadBalancer.ResourceGroupName)' after attempting to apply NAT Rules to LB config. Migration will continue, INBOUND NAT RULES WILL NEED TO BE MANUALLY ADDED to the load balancer. Error: $_"
log "Error" $message
}
}
Expand Down
Loading