-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTool - GUI IP Changer 1.05.ps1
589 lines (493 loc) · 23.3 KB
/
Tool - GUI IP Changer 1.05.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
<#
.NOTES
===========================================================================
Created on: 2022-4-27
Created by: Brian Thorp
===========================================================================
.Description
Winform Tool to change a machines IP Address to a list of pre-set addresses
#>
#===
$settings = `
@(
New-Object PSObject -Property @{DisplayName="System Default"; DHCP="$True"; IPAddress="0.0.0.0"; SubnetMask="24"; Gateway="0.0.0.0"; DNS="0.0.0.0"}
New-Object PSObject -Property @{DisplayName="Demo Settings 1"; DHCP="$False"; IPAddress="192.168.1.2"; SubnetMask="24"; Gateway="0.0.0.0"; DNS="0.0.0.0"}
New-Object PSObject -Property @{DisplayName="Demo Settings 2"; DHCP="$False"; IPAddress="172.16.1.2"; SubnetMask="24"; Gateway="0.0.0.0"; DNS="0.0.0.0"}
New-Object PSObject -Property @{DisplayName="Demo Settings 3"; DHCP="$False"; IPAddress="10.0.0.2"; SubnetMask="24"; Gateway="0.0.0.0"; DNS="0.0.0.0"}
)
# Get the Ethernet Adapter
$adapter = Get-NetAdapter | Where-Object { $_.Name -eq "Ethernet" }
function Get-CurrentConfig
{
param(
$Adapter
)
# # Write-Host "==============================================="
# Write-Host "Function Get-CurrentConfig"
# Write-Host "==============================================="
$Interface = $adapter.InterfaceDescription # $CurrentSettings.InterfaceDescription
# Does the adapter exist?
$AdapterReady = ((Get-NetIPConfiguration).InterfaceIndex) -contains $adapter.ifIndex # 800ms
if ($AdapterReady)
{
$AdapterDetails = ($adapter | Get-NetIPConfiguration)
$IP = $AdapterDetails.IPv4Address.IPAddress
$CIDR = $AdapterDetails.IPv4Address.PrefixLength
$Gateway = $AdapterDetails.IPv4DefaultGateway.NextHop
# Fix for DNS not having a value - test and ignore otherwise
$PreDNS = $AdapterDetails.DNSServer.ServerAddresses
if (!([string]::IsNullOrEmpty($PreDNS))) # if this is null or empty then we abort
{
$DNS = $PreDNS[1] # Select only the first one, Primary DNS
}
$xDHCP = ($adapter | Get-NetIPInterface -ifIndex $adapter.ifindex).DHCP
# Write-Host "DNS: $DNS"
$AllDNS = $AdapterDetails.DNSServer.ServerAddresses
# Write-Host "All DNS: $ALLDns"
if ($xDHCP -like "Enabled") { $dhcp = $true}
if ($xDHCP -like "Disabled") { $dhcp = $false}
}
if (!$AdapterReady)
{
# Show Error Message~
# Write-Host "Error - Adapter is not ready" -ForegroundColor "Red"
$StatusTextBox.AppendText("Error with adapter`r`n")
}
if ($AdapterReady)
{
# Write-Host "Adapter is determined to be ready, loading values to write to GUI" -ForegroundColor "Green"
<#
$CurrentIP = $StartCurrent.IP
$CurrentCIDR = $StartCurrent.CIDR
$CurrentGateway = $StartCurrent.Gateway
$CurrentDNS = $StartCurrent.DNS
$CurrentDHCP = $StartCurrent.DHCP
# Write-Host ""
# Write-Host ""
# Write-Host ""
# Write-Host ""
# Write-Host ""
#>
# Write-Host "Updating GUI with current settings"
$CurrentDHCPLabel.Text = "$DHCP"
$CurrentIPLabel.Text = "$IP"
$CurrentCIDRLabel.Text = "$CIDR"
$CurrentGatewayLabel.Text = "$Gateway"
$CurrentDNSLabel.Text = "$DNS"
#$results = @($DHCP,$IP,$CIDR,$Gateway,$DNS)
# Write-Host "Ready" -ForegroundColor "Green"
$StatusTextBox.AppendText("Ready`r`n")
}
$results = New-Object PsObject -Property @{AdapterReady=$adapterready; Interface = $Interface; DHCP=$DHCP; IP=$IP; CIDR=$CIDR; Gateway=$Gateway;DNS=$DNS}
Return $results
}
# Get-CurrentConfig -Adapter $Adapter
# https://stackoverflow.com/questions/27690918/array-find-and-indexof-for-multiple-elements-that-are-exactly-the-same-object
function get-IndicesOf($Array, $Value)
{
$i = 0
foreach ($el in $Array)
{
if ($el -eq $Value) { $i }
++$i
}
}
function Set-Ethernet
{
param(
$DHCP,
$adapter,
$IP,
$MaskBits,
$Gateway,
$DNS
)
# Write-Host "==============================================="
# Write-Host "Function - Set-Ethernet"
# Write-Host "==============================================="
write-host "DHCP is $dhcp"
$type = $dhcp.gettype()
# Write-Host "DHCP is $type"
if ($type -like "string")
{
if ($DHCP -like "True") {$dhcp = $true}
if ($DHCP -like "False") {$dhcp = $false}
}
$IPType = "IPv4"
# Retrieve the network adapter that you want to configure
if ($dhcp -eq $false)
{
write-host "DHCP is false so we'll apply IP configuration"
# Remove any existing IP, gateway from our ipv4 adapter
If (($adapter | Get-NetIPConfiguration).IPv4Address.IPAddress)
{
$adapter | Remove-NetIPAddress -AddressFamily $IPType -Confirm:$false
}
If (($adapter | Get-NetIPConfiguration).Ipv4DefaultGateway)
{
$adapter | Remove-NetRoute -AddressFamily $IPType -Confirm:$false
}
# Write-Host "Applying IP Configuration..."
$StatusTextBox.AppendText("Applying configuration...`r`n")
# Check for null Gateway
if ($Gateway -eq "0.0.0.0")
{
$adapter | New-NetIPAddress `
-AddressFamily $IPType `
-IPAddress $IP `
-PrefixLength $MaskBits `
#-DefaultGateway $Gateway
}
if ($Gateway -ne "0.0.0.0")
{
$adapter | New-NetIPAddress `
-AddressFamily $IPType `
-IPAddress $IP `
-PrefixLength $MaskBits `
-DefaultGateway $Gateway
}
# Configure the IP address and default gateway
# Configure the DNS client server IP addresses
$adapter | Set-DnsClientServerAddress -ServerAddresses $DNS
}
if ($dhcp)
{
write-host "DHCP is true so we'll clear and set to DHCP"
# Remove existing gateway
If (($adapter | Get-NetIPConfiguration).Ipv4DefaultGateway)
{
# Note - this will sometimes throw an error
$adapter | Remove-NetRoute -Confirm:$false
}
# Enable DHCP
$adapter | Set-NetIPInterface -DHCP Enabled
# Configure the DNS Servers automatically
$adapter | Set-DnsClientServerAddress -ResetServerAddresses
}
}
#region Form
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$Form1 = New-Object System.Windows.Forms.Form
$Form1.ClientSize = New-Object System.Drawing.Size(400, 220)
$form1.topmost = $true
$Form1.FormBorderStyle = "Fixed3D"
$Form1.MaximizeBox = $False
$Form1.Text = "Contoso IP Changer v1.05"
#endregion Form
#region Functions
Function Get-Values
{
# Write-Host "==============================================="
# Write-Host "Function - Get-Values"
# Write-Host "==============================================="
If ($ComboBox1.SelectedItem -lt 0)
{
$Selected = "No selection was made"
Write-host $Selected -ForegroundColor Red
}
Else
{
$Selected = $ComboBox1.SelectedItem.ToString()
Write-host "$Selected chosen" -ForegroundColor Green
# Write-Host "Breaking apart values for use..."
# What is selected?
$DisplayName = ($Settings.DisplayName)
$SelectedIndex = get-IndicesOf ($DisplayName) $Selected
# Write-Host $Selected
# Write-Host "Index: $SelectedIndex"
# Write-Host "DisplayName: $DisplayName"
$LoadedDHCP = $Settings.DHCP[$SelectedIndex]
$LoadedIP = $Settings.IPAddress[$SelectedIndex]
$LoadedCIDR = $Settings.SubnetMask[$SelectedIndex]
$LoadedGateway = $Settings.Gateway[$SelectedIndex]
$LoadedDNS = $Settings.DNS[$SelectedIndex]
$LoadedDHCPLabel.Text = "$LoadedDHCP"
$LoadedIPLabel.Text = "$LoadedIP"
$LoadedCIDRLabel.Text = "$LoadedCIDR"
$LoadedGatewayLabel.Text = "$LoadedGateway"
$LoadedDNSLabel.Text = "$LoadedDNS"
}
write-host $LoadedDHCP,$LoadedIP,$LoadedCIDR,$LoadedGateway,$LoadedDNS
# $results = New-Object PsObject -Property @{DHCP=$LoadedDHCP;IP=$LoadedIP;CIDR=$LoadedCIDR;Gateway=$LoadedGateway;DNS=$LoadedDNS}
$results = @($LoadedDHCP,$LoadedIP,$LoadedCIDR,$LoadedGateway,$LoadedDNS)
# Enable Apply Button
$ApplyButton1.Enabled = $True
# Write-Host "Ready" -ForegroundColor "Green"
$StatusTextBox.AppendText("Ready`r`n")
$Global:Load = $results
Return $results
}
Function Compare-IPSettings
{
param(
$CurrentSettings, # Current Settings
$TargetSettings # Target Settings
)
# Write-Host "==============================================="
# Write-Host "Function - Compare-IPSettings"
# Write-Host "==============================================="
# Write-Host "Current Settings: $CurrentSettings"
# Write-Host "Target Settings: $TargetSettings"
$TargetBlank = [string]::IsNullOrEmpty($TargetSettings)
$CurrentBlank = [string]::IsNullOrEmpty($CurrentSettings)
# Write-Host "Target is blank? $TargetBlank"
# Write-Host "Current is blank? $CurrentBlank"
# If one or the other is blank we'll just eject
if (!$TargetBlank -and !$CurrentBlank)
{
# Write-Host "Target and Current settings are not blank..."
$trigger = $TargetSettings[0]
# Write-Host "Target DHCP? $trigger"
# If the target is DHCP we'll ignore everything else and just compare these
if($trigger -like "True") # TODO
{
# Write-Host "Target settings are DHCP"
$Result = $TargetSettings[0] -eq $CurrentSettings[0]
}
else
{
# Write-Host "-----------------------------------------------"
$CDHCP = $CurrentSettings[0]
$CIP = $CurrentSettings[1]
$CCIDR = $CurrentSettings[2]
$CGateway = $CurrentSettings[3]
$CDNS = $CurrentSettings[4]
# Write-Host "Current Setting: DHCP is $CDHCP"
# Write-Host "Current Setting: IP is $CIP"
# Write-Host "Current Setting: Subnet is $CCIDR"
# Write-Host "Current Setting: Gateway is $CGateway"
# Write-Host "Current Setting: DNS is $CDNS"
# Fix wierd null stuff
if ([string]::IsNullOrEmpty($CGateway)) {$CGateway = "0.0.0.0"}
if ($CDNS -eq ".") {$CDNS = "0.0.0.0"}
# Write-Host "Corrected Values:"
# Write-Host "Current Setting: Gateway is $CGateway"
# Write-Host "Current Setting: DNS is $CDNS"
$UpdatedCurrent = $CDHCP, $CIP, $CCIDR, $CGateway, $CDNS
# Write-Host "-----------------------------------------------"
$TDHCP = $TargetSettings[0]
$TIP = $TargetSettings[1]
$TCIDR = $TargetSettings[2]
$TGateway = $TargetSettings[3]
$TDNS = $TargetSettings[4]
# Write-Host "Target Setting: DHCP is $TDHCP"
# Write-Host "Target Setting: IP is $TIP"
# Write-Host "Target Setting: Subnet is $TCIDR"
# Write-Host "Target Setting: Gateway is $TGateway"
# Write-Host "Target Setting: DNS is $TDNS"
$Compare = Compare-Object -ReferenceObject $TargetSettings -DifferenceObject $UpdatedCurrent
# Compare Object only shows what is different so its blank if its the same
$Result = [string]::IsNullOrEmpty($Compare)
}
if ($result) {$StatusTextBox.AppendText("Successfully Applied Settings!`r`n")}
return $result
}
}
Function Set-Values
{
param(
$Values,
$Adapter
)
# Write-Host "==============================================="
# Write-Host "Function - Set-Values"
# Write-Host "==============================================="
# Write-Host "Vales are: $Values"
# Write-Host "Adapter is: $Adapter"
# Rip values from array
$DHCP = $Values[0]
$IP = $Values[1]
$CIDR = $Values[2]
$Gateway = $Values[3]
$DNS = $Values[4]
# Write-Host $DHCP
# Write-Host $IP
# Write-Host $CIDR
# Write-Host $Gateway
# Write-Host $DNS
#Display Applying...
# Set the new values
Set-Ethernet -adapter $Adapter -DHCP $DHCP -IP $IP -MaskBits $CIDR -Gateway $Gateway -DNS $DNS
# Get the current values -> Function?
$StageUpdatedValues = Get-CurrentConfig -Adapter $Adapter
$UpdatedDHCP = $StageUpdatedValues.DHCP
$UpdatedIP = $StageUpdatedValues.IP
$UpdatedCIDR = $StageUpdatedValues.CIDR
$UpdatedGatway = $StageUpdatedValues.Gateway
$UpdatedDNS = $StageUpdatedValues.DNS
$UpdatedInterface = $StageUpdatedValues.Interface
$UpdatedAdapterRdy = $StageUpdatedValues.AdapterReady
$UpdatedValues = @($UpdatedDHCP,$UpdatedIP,$UpdatedCIDR,$UpdatedGatway,$UpdatedDNS)
# Compare current to what we wanted set
$Compare = Compare-IPSettings -CurrentSettings $UpdatedValues -TargetSettings $Load
Write-host "Set is: $Compare"
# If the compare is good, show Successful | Else Failed
# Write-Host "Succesful" -ForegroundColor "Green"
# Update
}
#endregion Functions
#region Dropdown
$comboBox1 = New-Object System.Windows.Forms.ComboBox
$comboBox1.Location = New-Object System.Drawing.Point(10, 8)
$comboBox1.Size = New-Object System.Drawing.Size(180, 20)
# Load the settings into the combo box dynamically
ForEach($item in $settings)
{
$box = $item.DisplayName
$comboBox1.Items.add("$box")
}
$ComboBox1.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList;
$ComboBox1.SelectedIndex = 0
$comboBox1.add_SelectedIndexChanged({Get-Values})
$Form1.Controls.Add($comboBox1)
#endregion Dropdown
#region Buttons
#region Load Button1
# $LoadButton1 = New-Object System.Windows.Forms.Button
# $LoadButton1.Size = New-Object System.Drawing.Size(70, 24)
# $LoadButton1.Location = New-Object System.Drawing.Size(180, 6)
# $LoadButton1.Text = "Load"
# $LoadButton1.Add_Click( { (Get-Values) }) #Test-Something
# $Form1.Controls.Add($LoadButton1)
#endregion Load Button1
$ApplyButton1 = New-Object System.Windows.Forms.Button
$ApplyButton1.Size = New-Object System.Drawing.Size(220, 24)
$ApplyButton1.Location = New-Object System.Drawing.Size(75, 130)
$ApplyButton1.Text = "Apply >>"
$ApplyButton1.Add_Click({ Set-Values -Values $Global:Load -Adapter $adapter; Get-CurrentConfig -Adapter $Adapter })
$ApplyButton1.Enabled = $False
$Form1.Controls.Add($ApplyButton1)
#endregion Buttons
#region Labels
$EthLabel = new-object System.Windows.Forms.Label
$EthLabel.Location = new-object System.Drawing.Size(10, 32)
$EthLabel.size = new-object System.Drawing.Size(300, 13)
$EthLabel.Text = "Current Interface: $CurrentInterface"
$Form1.Controls.Add($EthLabel)
$DHCPLabel = new-object System.Windows.Forms.Label
$DHCPLabel.Location = new-object System.Drawing.Size(12, 64)
$DHCPLabel.size = new-object System.Drawing.Size(108, 13)
$DHCPLabel.Text = "DHCP:"
$Form1.Controls.Add($DHCPLabel)
$IPLabel = new-object System.Windows.Forms.Label
$IPLabel.Location = new-object System.Drawing.Size(12, 77)
$IPLabel.size = new-object System.Drawing.Size(108, 13)
$IPLabel.Text = "IP Address:"
$Form1.Controls.Add($IPLabel)
$CIDRLabel = new-object System.Windows.Forms.Label
$CIDRLabel.Location = new-object System.Drawing.Size(12, 90)
$CIDRLabel.size = new-object System.Drawing.Size(108, 13)
$CIDRLabel.Text = "Subnet Mask:"
$Form1.Controls.Add($CIDRLabel)
$GatewayLabel = new-object System.Windows.Forms.Label
$GatewayLabel.Location = new-object System.Drawing.Size(12, 103)
$GatewayLabel.size = new-object System.Drawing.Size(108, 13)
$GatewayLabel.Text = "Gateway:"
$Form1.Controls.Add($GatewayLabel)
$DNSLabel = new-object System.Windows.Forms.Label
$DNSLabel.Location = new-object System.Drawing.Size(12, 116)
$DNSLabel.size = new-object System.Drawing.Size(108, 13)
$DNSLabel.Text = "DNS:"
$Form1.Controls.Add($DNSLabel)
$LoadedLabel = new-object System.Windows.Forms.Label
$LoadedLabel.Location = new-object System.Drawing.Size(130, 50)
$LoadedLabel.size = new-object System.Drawing.Size(108, 13)
$LoadedLabel.Text = "Loaded Settings"
$Form1.Controls.Add($LoadedLabel)
$CurrentLabel = new-object System.Windows.Forms.Label
$CurrentLabel.Location = new-object System.Drawing.Size(270, 50)
$CurrentLabel.size = new-object System.Drawing.Size(108, 13)
$CurrentLabel.Text = "Current Settings"
$Form1.Controls.Add($CurrentLabel)
# Labels for Current Adapter Settings
$CurrentDHCPLabel = new-object System.Windows.Forms.Label
$CurrentDHCPLabel.Location = new-object System.Drawing.Size(270, 64)
$CurrentDHCPLabel.size = new-object System.Drawing.Size(108, 13)
#$CurrentDHCPLabel.Text = "$CurrentDHCP"
$Form1.Controls.Add($CurrentDHCPLabel)
$CurrentIPLabel = new-object System.Windows.Forms.Label
$CurrentIPLabel.Location = new-object System.Drawing.Size(270, 77)
$CurrentIPLabel.size = new-object System.Drawing.Size(108, 13)
#$CurrentIPLabel.Text = "$CurrentIP"
$Form1.Controls.Add($CurrentIPLabel)
$CurrentCIDRLabel = new-object System.Windows.Forms.Label
$CurrentCIDRLabel.Location = new-object System.Drawing.Size(270, 90)
$CurrentCIDRLabel.size = new-object System.Drawing.Size(108, 13)
#$CurrentCIDRLabel.Text = "$CurrentCIDR"
$Form1.Controls.Add($CurrentCIDRLabel)
$CurrentGatewayLabel = new-object System.Windows.Forms.Label
$CurrentGatewayLabel.Location = new-object System.Drawing.Size(270, 103)
$CurrentGatewayLabel.size = new-object System.Drawing.Size(108, 13)
#$CurrentGatewayLabel.Text = "$CurrentGateway"
$Form1.Controls.Add($CurrentGatewayLabel)
$CurrentDNSLabel = new-object System.Windows.Forms.Label
$CurrentDNSLabel.Location = new-object System.Drawing.Size(270, 116)
$CurrentDNSLabel.size = new-object System.Drawing.Size(108, 13)
#$CurrentDNSLabel.Text = "$CurrentDNS"
$Form1.Controls.Add($CurrentDNSLabel)
# Labels for Loaded Adapter Settings
$LoadedDHCPLabel = new-object System.Windows.Forms.Label
$LoadedDHCPLabel.Location = new-object System.Drawing.Size(130, 64)
$LoadedDHCPLabel.size = new-object System.Drawing.Size(108, 13)
$LoadedDHCPLabel.Text = "$LoadedDHCP"
$Form1.Controls.Add($LoadedDHCPLabel)
$LoadedIPLabel = new-object System.Windows.Forms.Label
$LoadedIPLabel.Location = new-object System.Drawing.Size(130, 77)
$LoadedIPLabel.size = new-object System.Drawing.Size(108, 13)
$LoadedIPLabel.Text = "$LoadedIP"
$Form1.Controls.Add($LoadedIPLabel)
$LoadedCIDRLabel = new-object System.Windows.Forms.Label
$LoadedCIDRLabel.Location = new-object System.Drawing.Size(130, 90)
$LoadedCIDRLabel.size = new-object System.Drawing.Size(108, 13)
$LoadedCIDRLabel.Text = "$LoadedCIDR"
$Form1.Controls.Add($LoadedCIDRLabel)
$LoadedGatewayLabel = new-object System.Windows.Forms.Label
$LoadedGatewayLabel.Location = new-object System.Drawing.Size(130, 103)
$LoadedGatewayLabel.size = new-object System.Drawing.Size(108, 13)
$LoadedGatewayLabel.Text = "$LoadedGateway"
$Form1.Controls.Add($LoadedGatewayLabel)
$LoadedDNSLabel = new-object System.Windows.Forms.Label
$LoadedDNSLabel.Location = new-object System.Drawing.Size(130, 116)
$LoadedDNSLabel.size = new-object System.Drawing.Size(108, 13)
$LoadedDNSLabel.Text = "$LoadedDNS"
$Form1.Controls.Add($LoadedDNSLabel)
$StatusTextBox = New-Object System.Windows.Forms.TextBox
$StatusTextBox.Location = New-Object System.Drawing.Size(75, 160)
$StatusTextBox.Size = New-Object System.Drawing.Size(300, 50)
$StatusTextBox.Enabled = $False
$StatusTextBox.Multiline = $True
$StatusTextBox.AppendText("(Startup)`r`n")
$Form1.Controls.Add($StatusTextBox)
#endregion Labels
# =======================================================================
# Statup Main Code
# =======================================================================
# Run start - grab the current data
$StartCurrent = Get-CurrentConfig -Adapter $Adapter
# Get the adapter settings - Name
$CurrentInterface = $StartCurrent.Interface
# Does the adapter exist?
$AdapterReady = $StartCurrent.AdapterReady
# Write-Host "Main: Adapter is ready? $AdapterReady"
# These are updated after the GUI loads...TODO - fix this
<#
if ($AdapterReady)
{
# Write-Host "Adapter is determined to be ready, loading values to write to GUI"
$CurrentIP = $StartCurrent.IP
$CurrentCIDR = $StartCurrent.CIDR
$CurrentGateway = $StartCurrent.Gateway
$CurrentDNS = $StartCurrent.DNS
$CurrentDHCP = $StartCurrent.DHCP
}
if (!$AdapterReady)
{
# Write-Host "Error - Adapter is not ready" -ForegroundColor "Red"
$StatusTextBox.AppendText("Error with adapter - not ready`r`n")
# TODO - lock the app up?
}
#>
# =======================================================================
# Draw the form - should be last in code~
[void]$form1.showdialog()