Skip to content

Commit 1da0ffc

Browse files
Update Transfer-DHCPScopes.ps1
Signed-off-by: LUIZ HAMILTON ROBERTO DA SILVA <[email protected]>
1 parent 315046b commit 1da0ffc

1 file changed

Lines changed: 22 additions & 12 deletions

File tree

SysAdmin-Tools/Network-and-Infrastructure-Management/Transfer-DHCPScopes.ps1

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
Luiz Hamilton Silva - @brazilianscriptguy
1111
1212
.VERSION
13-
v4.5 – July 23, 2025
13+
v3.5 – July 23, 2025
1414
#>
1515

1616
#region --- Hide Console ---
@@ -174,7 +174,7 @@ function Import-DhcpScope {
174174
Write-Log "All scopes in $ImportFilePath already exist on $Server. No import performed." -Level "INFO"
175175
[Windows.Forms.MessageBox]::Show("All scopes already exist on $Server.`nNothing was imported.", "Info", "OK", "Information")
176176
$ProgressBar.Value = 100
177-
return $true
177+
return "Skipped"
178178
}
179179

180180
Import-DhcpServer -ComputerName $Server -File $ImportFilePath -Leases -BackupPath $global:ExportDir -ErrorAction Stop
@@ -188,11 +188,11 @@ function Import-DhcpScope {
188188
}
189189

190190
$ProgressBar.Value = 100
191-
return $true
191+
return "Imported"
192192
} catch {
193193
Write-Log "Import failed: $_" -Level "ERROR"
194194
$ProgressBar.Value = 0
195-
return $false
195+
return "Failed"
196196
}
197197
}
198198
#endregion
@@ -203,7 +203,7 @@ Add-Type -AssemblyName System.Drawing
203203

204204
function Show-GUI {
205205
$form = New-Object Windows.Forms.Form -Property @{
206-
Text = "DHCP Scope Transfer Tool v4.5"
206+
Text = "DHCP Scope Transfer Tool v3.5"
207207
Size = '720,460'
208208
StartPosition = 'CenterScreen'
209209
}
@@ -367,15 +367,25 @@ function Show-GUI {
367367
}
368368

369369
$lblStatusImport.Text = "Importing scope..."
370-
$success = Import-DhcpScope -Server $serverName -ImportFilePath $importFile `
370+
$result = Import-DhcpScope -Server $serverName -ImportFilePath $importFile `
371371
-InactivateAfter:$chkInactivateImp.Checked -ProgressBar $barImport
372372

373-
if ($success) {
374-
[Windows.Forms.MessageBox]::Show("Scope import process completed on server:`n$serverName", "Success", "OK", "Information")
375-
$lblStatusImport.Text = "Import completed"
376-
} else {
377-
[Windows.Forms.MessageBox]::Show("Import failed. Check log for details.", "Error", "OK", "Error")
378-
$lblStatusImport.Text = "Import failed"
373+
switch ($result) {
374+
"Imported" {
375+
[Windows.Forms.MessageBox]::Show("Scope import process completed on server:`n$serverName", "Success", "OK", "Information")
376+
$lblStatusImport.Text = "Import completed"
377+
}
378+
"Skipped" {
379+
$lblStatusImport.Text = "Nothing was imported"
380+
}
381+
"Failed" {
382+
[Windows.Forms.MessageBox]::Show("Import failed. Check log for details.", "Error", "OK", "Error")
383+
$lblStatusImport.Text = "Import failed"
384+
}
385+
default {
386+
[Windows.Forms.MessageBox]::Show("Unexpected result: $result", "Error", "OK", "Error")
387+
$lblStatusImport.Text = "Import failed"
388+
}
379389
}
380390
})
381391

0 commit comments

Comments
 (0)