-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerTempScript.ps1
More file actions
2458 lines (2170 loc) · 108 KB
/
Copy pathServerTempScript.ps1
File metadata and controls
2458 lines (2170 loc) · 108 KB
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
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<#
.NOTES
=============================================================================
Created with: VSCode
Created on: Monday, 16/6/2025 12:19 PM
Created by: Vibhu_Bhatnagar
Organization: Realtime
Filename version:6.0.0.0
=============================================================================
.DESCRIPTION
A complete Server inventory script that collects various system information, including:
- System Information
- Disk Information
- Network Information
- Share Information
- Printer Information
- Windows Updates
- Windows Features
- Installed Applications
- Windows Store Apps
- DHCP Information
- Active Directory Information
- Group Policy Information
- DNS Information
- RDS User Information
- Azure AD Join Status
- Privileged Users
- User login information on Terminal server
- GPO Information
- Active Directory Information
- Group Policy Information
- Bitlocker information
- Firewall information
- Windows Defender information
#>
# Function to get printer information
function Get-PrinterInformation
{
param ([string]$ComputerName)
try
{
$scriptBlock = {
$printers = Get-Printer | Select-Object Name, DriverName, PortName, Published, Shared, ShareName, Type, DeviceType
$drivers = Get-PrinterDriver | Select-Object Name, Manufacturer, InfPath
$combined = $printers | ForEach-Object {
$printer = $_
$driver = $drivers | Where-Object { $_.Name -eq $printer.DriverName }
[PSCustomObject]@{
PrinterName = $printer.Name
DriverName = $printer.DriverName
PortName = $printer.PortName
Published = $printer.Published
Shared = $printer.Shared
ShareName = $printer.ShareName
Type = $printer.Type
DeviceType = $printer.DeviceType
Manufacturer = $driver.Manufacturer
InfPath = $driver.InfPath
}
}
$combined
}
if ($ComputerName -eq $env:COMPUTERNAME)
{
$printerInfo = & $scriptBlock
}
else
{
$printerInfo = Invoke-Command -ComputerName $ComputerName -ScriptBlock $scriptBlock
}
return $printerInfo
}
catch
{
Write-Warning "Error collecting printer information: $_"
return $null
}
}
# Function to get Windows updates
function Get-WindowsUpdateInfo
{
param ([string]$ComputerName)
try
{
$params = @{}
if ($ComputerName -ne $env:COMPUTERNAME)
{
$params['ComputerName'] = $ComputerName
}
$updates = Get-HotFix @params | Select-Object Description, HotFixID, InstalledOn | Sort-Object InstalledOn -Descending
return $updates
}
catch
{
Write-Warning "Error collecting Windows updates: $_"
return $null
}
}
# Function to get Windows features
function Get-WindowsFeaturesInfo
{
param ([string]$ComputerName)
try
{
$scriptBlock = {
Get-WindowsFeature | Where-Object { $_.InstallState -eq "Installed" } |
Select-Object Name, DisplayName, InstallState, FeatureType
}
if ($ComputerName -eq $env:COMPUTERNAME)
{
$features = & $scriptBlock
}
else
{
$features = Invoke-Command -ComputerName $ComputerName -ScriptBlock $scriptBlock
}
$roles = $features | Where-Object { $_.FeatureType -eq "Role" }
$roleServices = $features | Where-Object { $_.FeatureType -eq "Role Service" }
$otherFeatures = $features | Where-Object { $_.FeatureType -eq "Feature" }
return @{
Roles = $roles
RoleServices = $roleServices
Features = $otherFeatures
AllFeatures = $features
}
}
catch
{
Write-Warning "Error collecting Windows features: $_"
return $null
}
}
# Function to get installed applications
function Get-InstalledApplications
{
param ([string]$ComputerName)
try
{
$scriptBlock = {
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*,
HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* -ErrorAction SilentlyContinue |
Where-Object { $_.DisplayName -ne $null } |
Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Sort-Object DisplayName
}
if ($ComputerName -eq $env:COMPUTERNAME)
{
$formattedApps = & $scriptBlock
}
else
{
$formattedApps = Invoke-Command -ComputerName $ComputerName -ScriptBlock $scriptBlock
}
return $formattedApps
}
catch
{
Write-Warning "Error collecting installed applications: $_"
return $null
}
}
# Function to get Windows Store apps
function Get-WindowsStoreApps
{
param ([string]$ComputerName)
try
{
$scriptBlock = {
Get-AppxPackage | Select-Object Name, Version, Publisher, Architecture | Sort-Object Name
}
if ($ComputerName -eq $env:COMPUTERNAME)
{
$formattedStoreApps = & $scriptBlock
}
else
{
$formattedStoreApps = Invoke-Command -ComputerName $ComputerName -ScriptBlock $scriptBlock
}
return $formattedStoreApps
}
catch
{
Write-Warning "Error collecting Windows Store applications: $_"
return $null
}
}
#_________________________________________________________________________________________________
# Function to get DHCP information
function Get-DHCPInformation
{
param ([string]$ComputerName)
try
{
$scopes = Get-DhcpServerv4Scope -ComputerName $ComputerName
$serverOptions = Get-DhcpServerv4OptionValue -ComputerName $ComputerName
if ($scopes)
{
$reservations = Get-DhcpServerv4Reservation -ComputerName $ComputerName -ScopeId $scopes.ScopeId
}
else
{
$reservations = $null
}
$ipv6Scopes = Get-DhcpServerv6Scope -ComputerName $ComputerName
if ($ipv6Scopes)
{
$ipv6ServerOptions = Get-DhcpServerv6OptionValue -ComputerName $ComputerName
$ipv6Reservations = Get-DhcpServerv6Reservation -ComputerName $ComputerName -ScopeId $ipv6Scopes.ScopeId
}
else
{
$ipv6ServerOptions = $null
$ipv6Reservations = $null
}
$dhcpv4DnsSettings = Get-DhcpServerv4DnsSetting -ComputerName $ComputerName
$dhcpv6DnsSettings = Get-DhcpServerv6DnsSetting -ComputerName $ComputerName
return @{
Scopes = $scopes
ServerOptions = $serverOptions
Reservations = $reservations
IPv6Scopes = $ipv6Scopes
IPv6ServerOptions = $ipv6ServerOptions
IPv6Reservations = $ipv6Reservations
DHCPv4DnsSettings = $dhcpv4DnsSettings
DHCPv6DnsSettings = $dhcpv6DnsSettings
}
}
catch
{
Write-Warning "Error collecting DHCP information: $_"
return $null
}
}
function Get-VBDhcpInfo {
<#
.SYNOPSIS
Comprehensive DHCP server analysis and reporting tool for IPv4 and IPv6 configurations.
.DESCRIPTION
Get-VBDhcpInfo provides detailed analysis of DHCP server configurations including scopes,
reservations, exclusions, server options, and utilization statistics. The function supports
both local and remote DHCP servers with enhanced visual reporting and structured object output.
Features include:
- IPv4 and IPv6 scope analysis
- Static reservation inventory
- Exclusion range reporting
- Pool utilization statistics
- Server options summary
- DNS configuration details
- Lease duration information
- Visual console reporting with color-coded status indicators
- Pipeline support for multiple servers
.PARAMETER ComputerName
Specifies the DHCP server(s) to analyze. Accepts pipeline input and supports multiple servers.
Default value is the local computer name.
.PARAMETER Credential
Specifies credentials for remote server authentication. Use Get-Credential to create PSCredential object.
.EXAMPLE
Get-VBDhcpInfo
Analyzes the local DHCP server configuration and displays comprehensive report with visual formatting.
.EXAMPLE
Get-VBDhcpInfo -ComputerName "DHCP-SRV01"
Connects to remote DHCP server DHCP-SRV01 and generates detailed configuration analysis.
.EXAMPLE
"DHCP-SRV01", "DHCP-SRV02" | Get-VBDhcpInfo -Credential (Get-Credential)
Analyzes multiple DHCP servers using pipeline input with specified credentials for authentication.
.EXAMPLE
$dhcpData = Get-VBDhcpInfo -ComputerName "DHCP-SRV01"
$dhcpData.IPv4Scopes | Where-Object State -eq "Active"
Captures DHCP analysis data and filters to show only active IPv4 scopes for further processing.
.EXAMPLE
Get-VBDhcpInfo | Where-Object UtilizationPercent -gt 80
Identifies DHCP servers with high IP pool utilization (over 80%) for capacity planning.
.OUTPUTS
PSCustomObject
Returns structured object containing:
- ComputerName: Target DHCP server name
- ScanDateTime: Analysis timestamp
- IPv4ScopeCount: Number of IPv4 scopes
- IPv4Scopes: Detailed scope information including lease duration
- IPv4Reservations: Static IP reservations
- IPv4Exclusions: Excluded IP ranges
- TotalIPPool: Total available IP addresses
- UsedIPs: Currently assigned IP addresses
- UtilizationPercent: Pool utilization percentage
- IPv6ScopeCount: Number of IPv6 scopes
- IPv6Scopes: IPv6 scope details
- IPv6Reservations: IPv6 static reservations
- IPv4DnsSettings: IPv4 DNS configuration
- IPv6DnsSettings: IPv6 DNS configuration
- Status: Success/Failed status
.NOTES
Version: 1.1
Author: IT Administration Team
Category: DHCP Management
Requirements:
- DHCP Server PowerShell module
- Administrative privileges on target DHCP servers
- Network connectivity to remote servers
- PowerShell 5.1 or later
Compatible with:
- Windows Server 2012 R2 and later
- Windows Server Core installations
- Clustered DHCP configurations
#>
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[Alias('Name', 'Server')]
[string[]]$ComputerName = $env:COMPUTERNAME,
[PSCredential]$Credential
)
process {
foreach ($computer in $ComputerName) {
try {
$params = @{ ComputerName = $computer }
if ($Credential) { $params.Credential = $Credential }
# Header with fancy formatting
Write-Host ("`n" + ("="*80)) -ForegroundColor Magenta
Write-Host "🌐 DHCP SERVER ANALYSIS REPORT" -ForegroundColor Cyan
Write-Host "📍 Server: $computer" -ForegroundColor Green
Write-Host "🕒 Scan Time: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')" -ForegroundColor Gray
Write-Host ("="*80) -ForegroundColor Magenta
# IPv4 Information
$scopes = @(Get-DhcpServerv4Scope @params -ErrorAction SilentlyContinue)
$serverOptions = Get-DhcpServerv4OptionValue @params -ErrorAction SilentlyContinue
$allReservations = @()
$totalAddresses = 0
$usedAddresses = 0
if ($scopes.Count -gt 0) {
foreach ($scope in $scopes) {
$scopeReservations = Get-DhcpServerv4Reservation @params -ScopeId $scope.ScopeId -ErrorAction SilentlyContinue
if ($scopeReservations) {
$allReservations += $scopeReservations
}
# Calculate scope statistics
$scopeStats = Get-DhcpServerv4ScopeStatistics @params -ScopeId $scope.ScopeId -ErrorAction SilentlyContinue
if ($scopeStats) {
$totalAddresses += $scopeStats.AddressesFree + $scopeStats.AddressesInUse
$usedAddresses += $scopeStats.AddressesInUse
}
}
}
# IPv6 Information
$ipv6Scopes = @(Get-DhcpServerv6Scope @params -ErrorAction SilentlyContinue)
$ipv6ServerOptions = if ($ipv6Scopes.Count -gt 0) { Get-DhcpServerv6OptionValue @params -ErrorAction SilentlyContinue }
$allIPv6Reservations = @()
if ($ipv6Scopes.Count -gt 0) {
foreach ($scope in $ipv6Scopes) {
$scopeReservations = Get-DhcpServerv6Reservation @params -ScopeId $scope.ScopeId -ErrorAction SilentlyContinue
if ($scopeReservations) {
$allIPv6Reservations += $scopeReservations
}
}
}
$dhcpv4DnsSettings = Get-DhcpServerv4DnsSetting @params -ErrorAction SilentlyContinue
$dhcpv6DnsSettings = Get-DhcpServerv6DnsSetting @params -ErrorAction SilentlyContinue
# Executive Summary Box
Write-Host ("`n┌─ 📊 EXECUTIVE SUMMARY " + ("─"*50) + "┐") -ForegroundColor Yellow
Write-Host "│" -ForegroundColor Yellow -NoNewline
Write-Host " 🔢 IPv4 Scopes: " -ForegroundColor White -NoNewline
Write-Host ("{0,2}" -f $scopes.Count) -ForegroundColor Cyan -NoNewline
Write-Host " │ 🏠 Total IP Pool: " -ForegroundColor White -NoNewline
Write-Host ("{0,6}" -f $totalAddresses) -ForegroundColor Green -NoNewline
Write-Host " │ 🔴 Used: " -ForegroundColor White -NoNewline
Write-Host ("{0,4}" -f $usedAddresses) -ForegroundColor Red -NoNewline
Write-Host " │" -ForegroundColor Yellow
Write-Host "│" -ForegroundColor Yellow -NoNewline
Write-Host " 📋 IPv4 Reservations: " -ForegroundColor White -NoNewline
Write-Host ("{0,2}" -f $allReservations.Count) -ForegroundColor Magenta -NoNewline
Write-Host " │ 🌍 IPv6 Scopes: " -ForegroundColor White -NoNewline
Write-Host ("{0,2}" -f $ipv6Scopes.Count) -ForegroundColor Cyan -NoNewline
Write-Host " │ 📋 IPv6 Res: " -ForegroundColor White -NoNewline
Write-Host ("{0,2}" -f $allIPv6Reservations.Count) -ForegroundColor Magenta -NoNewline
Write-Host " │" -ForegroundColor Yellow
$utilizationPercent = if ($totalAddresses -gt 0) { [math]::Round(($usedAddresses / $totalAddresses) * 100, 1) } else { 0 }
Write-Host "│" -ForegroundColor Yellow -NoNewline
Write-Host " 📈 Pool Utilization: " -ForegroundColor White -NoNewline
$utilizationColor = if ($utilizationPercent -lt 70) { "Green" } elseif ($utilizationPercent -lt 90) { "Yellow" } else { "Red" }
Write-Host ("{0}%" -f $utilizationPercent) -ForegroundColor $utilizationColor -NoNewline
Write-Host (" " * (52 - " 📈 Pool Utilization: $utilizationPercent%".Length)) -NoNewline
Write-Host "│" -ForegroundColor Yellow
Write-Host ("└" + ("─"*78) + "┘") -ForegroundColor Yellow
# IPv4 Scope Details with enhanced formatting
if ($scopes.Count -gt 0) {
Write-Host ("`n┌─ 🌐 IPv4 SCOPE CONFIGURATION " + ("─"*44) + "┐") -ForegroundColor Cyan
foreach ($scope in $scopes) {
$scopeStats = Get-DhcpServerv4ScopeStatistics @params -ScopeId $scope.ScopeId -ErrorAction SilentlyContinue
Write-Host "│" -ForegroundColor Cyan
Write-Host "├─ 🏷️ Scope: " -ForegroundColor Green -NoNewline
Write-Host $scope.ScopeId -ForegroundColor White -NoNewline
Write-Host " ($($scope.Name))" -ForegroundColor Yellow
Write-Host "│ 📡 Range: " -ForegroundColor Gray -NoNewline
Write-Host "$($scope.StartRange) → $($scope.EndRange)" -ForegroundColor White
Write-Host "│ 🎭 Subnet: " -ForegroundColor Gray -NoNewline
Write-Host $scope.SubnetMask -ForegroundColor White -NoNewline
# Add lease duration information
Write-Host " │ ⏰ Lease: " -ForegroundColor Gray -NoNewline
$leaseDurationDisplay = if ($scope.LeaseDuration -eq "10675199.02:48:05.4775807") {
"Unlimited"
} else {
$scope.LeaseDuration.ToString()
}
Write-Host $leaseDurationDisplay -ForegroundColor Cyan
if ($scopeStats) {
$scopeUtil = if (($scopeStats.AddressesFree + $scopeStats.AddressesInUse) -gt 0) {
[math]::Round(($scopeStats.AddressesInUse / ($scopeStats.AddressesFree + $scopeStats.AddressesInUse)) * 100, 1)
} else { 0 }
Write-Host "│ 📊 Usage: " -ForegroundColor Gray -NoNewline
$scopeUtilColor = if ($scopeUtil -lt 70) { "Green" } elseif ($scopeUtil -lt 90) { "Yellow" } else { "Red" }
Write-Host "$scopeUtil%" -ForegroundColor $scopeUtilColor -NoNewline
Write-Host " ($($scopeStats.AddressesInUse)/$($scopeStats.AddressesFree + $scopeStats.AddressesInUse))" -ForegroundColor Gray
}
Write-Host "│ ⚙️ State: " -ForegroundColor Gray -NoNewline
$stateColor = if ($scope.State -eq "Active") { "Green" } else { "Red" }
Write-Host $scope.State -ForegroundColor $stateColor
}
Write-Host ("└" + ("─"*78) + "┘") -ForegroundColor Cyan
}
# IPv4 Reservations and Exclusions
Write-Host ("`n┌─ 📋 IPv4 RESERVATIONS & EXCLUSIONS " + ("─"*36) + "┐") -ForegroundColor Magenta
# Get exclusion ranges for each scope
$allExclusions = @()
foreach ($scope in $scopes) {
$exclusions = Get-DhcpServerv4ExclusionRange @params -ScopeId $scope.ScopeId -ErrorAction SilentlyContinue
if ($exclusions) {
$allExclusions += $exclusions | ForEach-Object {
[PSCustomObject]@{
ScopeId = $scope.ScopeId
StartRange = $_.StartRange
EndRange = $_.EndRange
}
}
}
}
if ($allReservations.Count -gt 0) {
Write-Host "├─ 🎯 STATIC RESERVATIONS:" -ForegroundColor Yellow
Write-Host "│ " -ForegroundColor Magenta -NoNewline
Write-Host ("{0,-15} {1,-18} {2,-20} {3}" -f "IP Address", "MAC Address", "Client Name", "Description") -ForegroundColor Yellow
Write-Host "│ " -ForegroundColor Magenta -NoNewline
Write-Host ("-"*15 + " " + "-"*18 + " " + "-"*20 + " " + "-"*20) -ForegroundColor Gray
foreach ($reservation in $allReservations) {
Write-Host "│ " -ForegroundColor Magenta -NoNewline
Write-Host ("{0,-15}" -f $reservation.IPAddress) -ForegroundColor White -NoNewline
Write-Host " {0,-18}" -f $reservation.ClientId -ForegroundColor Cyan -NoNewline
$reservationName = if ($reservation.Name) { $reservation.Name } else { "N/A" }
$reservationDesc = if ($reservation.Description) { $reservation.Description } else { "" }
Write-Host " {0,-20}" -f $reservationName -ForegroundColor Green -NoNewline
Write-Host " {0}" -f $reservationDesc -ForegroundColor Gray
}
} else {
Write-Host "├─ 🎯 STATIC RESERVATIONS:" -ForegroundColor Yellow
Write-Host "│ ℹ️ No static IP reservations configured" -ForegroundColor Gray
}
if ($allExclusions.Count -gt 0) {
Write-Host "│" -ForegroundColor Magenta
Write-Host "├─ 🚫 EXCLUDED IP RANGES:" -ForegroundColor Red
Write-Host "│ " -ForegroundColor Magenta -NoNewline
Write-Host ("{0,-15} {1,-15} {2}" -f "Scope", "Start Range", "End Range") -ForegroundColor Yellow
Write-Host "│ " -ForegroundColor Magenta -NoNewline
Write-Host ("-"*15 + " " + "-"*15 + " " + "-"*15) -ForegroundColor Gray
foreach ($exclusion in $allExclusions) {
Write-Host "│ " -ForegroundColor Magenta -NoNewline
Write-Host ("{0,-15}" -f $exclusion.ScopeId) -ForegroundColor White -NoNewline
Write-Host " {0,-15}" -f $exclusion.StartRange -ForegroundColor Red -NoNewline
Write-Host " {0}" -f $exclusion.EndRange -ForegroundColor Red
}
} else {
Write-Host "│" -ForegroundColor Magenta
Write-Host "├─ 🚫 EXCLUDED IP RANGES:" -ForegroundColor Red
Write-Host "│ ℹ️ No IP exclusion ranges configured" -ForegroundColor Gray
}
Write-Host ("└" + ("─"*78) + "┘") -ForegroundColor Magenta
# IPv6 Information (if present)
if ($ipv6Scopes.Count -gt 0) {
Write-Host ("`n┌─ 🌍 IPv6 CONFIGURATION " + ("─"*49) + "┐") -ForegroundColor Blue
foreach ($scope in $ipv6Scopes) {
Write-Host "│ 🏷️ Scope: " -ForegroundColor Green -NoNewline
Write-Host "$($scope.ScopeId) - $($scope.Name)" -ForegroundColor White
Write-Host "│ 📡 Prefix: " -ForegroundColor Gray -NoNewline
Write-Host $scope.Prefix -ForegroundColor White -NoNewline
Write-Host " │ ⏰ Lease: " -ForegroundColor Gray -NoNewline
$v6LeaseDurationDisplay = if ($scope.PreferredLifetime -eq "10675199.02:48:05.4775807") {
"Unlimited"
} else {
$scope.PreferredLifetime.ToString()
}
Write-Host $v6LeaseDurationDisplay -ForegroundColor Cyan
}
if ($allIPv6Reservations.Count -gt 0) {
Write-Host "│" -ForegroundColor Blue
Write-Host "├─ IPv6 Reservations:" -ForegroundColor Yellow
foreach ($reservation in $allIPv6Reservations) {
Write-Host "│ • " -ForegroundColor Blue -NoNewline
Write-Host "$($reservation.IPAddress) - $($reservation.ClientId) - $($reservation.Name)" -ForegroundColor White
}
}
Write-Host ("└" + ("─"*78) + "┘") -ForegroundColor Blue
}
# Server Options Summary
if ($serverOptions -or $ipv6ServerOptions) {
Write-Host ("`n┌─ ⚙️ SERVER OPTIONS SUMMARY " + ("─"*44) + "┐") -ForegroundColor DarkYellow
if ($serverOptions) {
Write-Host "│ 🔧 IPv4 Options Configured: " -ForegroundColor White -NoNewline
Write-Host $serverOptions.Count -ForegroundColor Green
}
if ($ipv6ServerOptions) {
Write-Host "│ 🔧 IPv6 Options Configured: " -ForegroundColor White -NoNewline
Write-Host $ipv6ServerOptions.Count -ForegroundColor Green
}
Write-Host ("└" + ("─"*78) + "┘") -ForegroundColor DarkYellow
}
# Footer
Write-Host ("`n" + ("="*80)) -ForegroundColor Magenta
Write-Host "✅ DHCP Analysis Complete - Data collection successful!" -ForegroundColor Green
Write-Host ("="*80) -ForegroundColor Magenta
# Return enhanced structured object
[PSCustomObject]@{
PSTypeName = 'VB.DhcpInfo'
ComputerName = $computer
ScanDateTime = Get-Date
IPv4ScopeCount = $scopes.Count
IPv4Scopes = $scopes
IPv4Options = $serverOptions
IPv4Reservations = $allReservations
IPv4ReservationCount = $allReservations.Count
IPv4Exclusions = $allExclusions
IPv4ExclusionCount = $allExclusions.Count
TotalIPPool = $totalAddresses
UsedIPs = $usedAddresses
UtilizationPercent = $utilizationPercent
IPv6ScopeCount = $ipv6Scopes.Count
IPv6Scopes = $ipv6Scopes
IPv6Options = $ipv6ServerOptions
IPv6Reservations = $allIPv6Reservations
IPv6ReservationCount = $allIPv6Reservations.Count
IPv4DnsSettings = $dhcpv4DnsSettings
IPv6DnsSettings = $dhcpv6DnsSettings
Status = 'Success'
}
}
catch {
Write-Host "`n❌ ERROR: Failed to collect DHCP information from $computer" -ForegroundColor Red
Write-Host " 📋 Details: $($_.Exception.Message)" -ForegroundColor Yellow
[PSCustomObject]@{
PSTypeName = 'VB.DhcpInfo'
ComputerName = $computer
Error = $_.Exception.Message
Status = 'Failed'
}
}
}
}
}
# Function to get Azure AD Join status
function Get-AzureADJoinStatus
{
param ([string]$ComputerName = $env:COMPUTERNAME)
try
{
# Grab whatever dsregcmd emits
$scriptBlock = {
$status = dsregcmd /status 2>&1
if ($status)
{
# Joined (or at least we got output)—return the full status
return $status
}
else
{
# No output ⇒ not joined
return "Server is NOT Azure AD Joined."
}
}
if ($ComputerName -eq $env:COMPUTERNAME)
{
return & $scriptBlock
}
else
{
return Invoke-Command -ComputerName $ComputerName -ScriptBlock $scriptBlock
}
}
catch
{
# Command itself failed ⇒ treat as not joined
return "Server is NOT Azure AD Joined."
}
}
# Helper function for Azure AD Join status (simplified version)
function Get-AzureADJoinStatusSimple
{
param ([string]$ComputerName = $env:COMPUTERNAME)
try
{
$scriptBlock = {
if (dsregcmd /status 2>&1)
{
Write-Output '✅ Joined to Azure AD'
}
else
{
Write-Output '❌ Not joined'
}
}
if ($ComputerName -eq $env:COMPUTERNAME)
{
return & $scriptBlock
}
else
{
return Invoke-Command -ComputerName $ComputerName -ScriptBlock $scriptBlock
}
}
catch
{
return "❌ Not joined"
}
}
# Function to get Active Directory information
function Get-ActiveDirectoryInfo
{
param ([string]$ComputerName)
try
{
if (-not (Get-Module -Name ActiveDirectory -ErrorAction SilentlyContinue))
{
Import-Module ActiveDirectory -ErrorAction Stop
}
$domainControllers = Get-ADDomainController -Filter * | Select-Object Name, Domain, Forest, OperationMasterRoles, IsReadOnly
$allServers = Get-ADComputer -Filter { OperatingSystem -Like "Windows Server*" } -Property * | Select-Object Name, IPv4Address, OperatingSystem, OperatingSystemVersion, ENABLED, LastLogonDate, WhenCreated | Sort-Object OperatingSystemVersion
$fsmoRoles = [PSCustomObject]@{
InfrastructureMaster = (Get-ADDomain).InfrastructureMaster
PDCEmulator = (Get-ADDomain).PDCEmulator
RIDMaster = (Get-ADDomain).RIDMaster
DomainNamingMaster = (Get-ADForest).DomainNamingMaster
SchemaMaster = (Get-ADForest).SchemaMaster
}
$domainFunctionalLevel = (Get-ADDomain).DomainMode
$forestFunctionalLevel = (Get-ADForest).ForestMode
$recycleBinEnabled = (Get-ADOptionalFeature -Filter { Name -eq 'Recycle Bin Feature' }).EnabledScopes.Count -gt 0
$tombstoneLifetime = (Get-ADObject -Identity "CN=Directory Service,CN=Windows NT,CN=Services,$((Get-ADRootDSE).configurationNamingContext)" -Properties tombstoneLifetime).tombstoneLifetime
$users = Get-ADUser -Filter * -Properties SamAccountName, ProfilePath, ScriptPath, homeDrive, homeDirectory
$userFolderReport = foreach ($user in $users)
{
[PSCustomObject]@{
SamAccountName = $user.SamAccountName
ProfilePath = if ([string]::IsNullOrEmpty($user.ProfilePath)) { "N/A" } else { $user.ProfilePath }
LogonScript = if ([string]::IsNullOrEmpty($user.ScriptPath)) { "N/A" } else { $user.ScriptPath }
HomeDrive = if ([string]::IsNullOrEmpty($user.homeDrive)) { "N/A" } else { $user.homeDrive }
HomeDirectory = if ([string]::IsNullOrEmpty($user.homeDirectory)) { "N/A" } else { $user.homeDirectory }
}
}
$totalUsers = $users.Count
$scriptBlock = {
if (Test-Path -Path "C:\Windows\SYSVOL\sysvol")
{
$folderpath = (Get-ChildItem "C:\Windows\SYSVOL\sysvol" | Where-Object { $_.PSIsContainer } | Select-Object -First 1).FullName
Get-ChildItem -Recurse -Path "$folderpath" -ErrorAction SilentlyContinue |
Where-Object { $_.Extension -in ".bat", ".cmd", ".ps1", ".vbs", ".exe", ".msi" } |
Select-Object FullName, Length, LastWriteTime
}
else
{
Write-Output "SYSVOL path not found"
}
}
if ($ComputerName -eq $env:COMPUTERNAME)
{
$sysvolScripts = & $scriptBlock
}
else
{
$sysvolScripts = Invoke-Command -ComputerName $ComputerName -ScriptBlock $scriptBlock
}
$PUsers = @()
try
{
$Members = Get-ADGroupMember -Identity 'Enterprise Admins' -Recursive -ErrorAction SilentlyContinue | Sort-Object Name
$PUsers += foreach ($Member in $Members)
{
Get-ADUser -Identity $Member.SID -Properties * | Select-Object Name, @{Name = 'Group'; expression = { 'Enterprise Admins' } }, WhenCreated, LastLogonDate, SamAccountName
}
}
catch
{
Write-Warning "Enterprise Admins group not found or cannot be accessed"
}
try
{
$Members = Get-ADGroupMember -Identity 'Domain Admins' -Recursive | Sort-Object Name
$PUsers += foreach ($Member in $Members)
{
Get-ADUser -Identity $Member.SID -Properties * | Select-Object Name, @{Name = 'Group'; expression = { 'Domain Admins' } }, WhenCreated, LastLogonDate, SamAccountName
}
}
catch
{
Write-Warning "Domain Admins group not found or cannot be accessed"
}
try
{
$Members = Get-ADGroupMember -Identity 'Schema Admins' -Recursive -ErrorAction SilentlyContinue | Sort-Object Name
$PUsers += foreach ($Member in $Members)
{
Get-ADUser -Identity $Member.SID -Properties * | Select-Object Name, @{Name = 'Group'; expression = { 'Schema Admins' } }, WhenCreated, LastLogonDate, SamAccountName
}
}
catch
{
Write-Warning "Schema Admins group not found or cannot be accessed"
}
try
{
$forestFunctionalLevel = (Get-ADForest).ForestMode
$domainFunctionalLevel = (Get-ADDomain).DomainMode
}
catch
{
Write-Warning "Can't detect functional levels"
}
# Check if AD recyclebin is enabled
try
{
$RecyclebinStatus = if ((Get-ADOptionalFeature -Filter 'Name -eq "Recycle Bin Feature"').EnabledScopes) { "✅ ENABLED" } else { "❌ Recycle Bin is NOT enabled" }
}
catch
{
Write-Warning "Can't detect Recyclebin status"
}
# Get Azure AD Join Status using the function
$AzureADJoinStatus = Get-AzureADJoinStatusSimple
return @{
DomainControllers = $domainControllers
AllServers = $allServers
FSMORoles = $fsmoRoles
UserFolderReport = $userFolderReport
SysvolScripts = $sysvolScripts
PrivilegedUsers = $PUsers
DomainFunctionalLevel = $domainFunctionalLevel
ForestFunctionalLevel = $forestFunctionalLevel
RecycleBinEnabled = $recycleBinEnabled
TombstoneLifetime = $tombstoneLifetime
DomainFunctLev = $domainFunctionalLevel
ForestFunLev = $forestFunctionalLevel
TotalADUsers = $totalUsers
ADRecyclebin = $RecyclebinStatus
AzureADJoinStatus = $AzureADJoinStatus
}
}
catch
{
Write-Warning "Error collecting Active Directory information: $_"
return $null
}
}
#___________________________________________________________________________________________________________________
#function to get Group policy Information
function Get-GPOInformation
{
[CmdletBinding()]
param()
# Ensure the GroupPolicy module is loaded
if (-not (Get-Module -Name GroupPolicy -ListAvailable))
{
Import-Module GroupPolicy -ErrorAction Stop
}
# Retrieve all GPOs
$gpos = Get-GPO -All
# If no GPOs were found, error out
if (-not $gpos)
{
Write-Error "No Group Policy Objects found in the domain."
return
}
else
{
# Select and display all desired properties
$gpos |
Select-Object `
Id,
DisplayName,
GpoStatus,
ModificationTime,
CreationTime,
Description |
Sort-Object -Property ModificationTime |
Format-Table -AutoSize
}
}
# Function to get DNS information
<# old function Get-DNSInformation
{
param ([string]$ComputerName)
try
{
$dnsServer = Get-DnsServer -ComputerName $ComputerName
$dnsSettings = Get-DnsServerSetting -ComputerName $ComputerName
$dnsForwarders = Get-DnsServerForwarder -ComputerName $ComputerName
return @{
DNSServer = $dnsServer
DNSSettings = $dnsSettings
DNSForwarders = $dnsForwarders
}
}
catch
{
Write-Warning "Error collecting DNS information: $_"
return $null
}
}
#>
#__________________________________________________________________________________________________
# Function to get DNS information
function Get-VBDNSServerInfo
{
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline = $true)]
[string[]]$ComputerName = $env:COMPUTERNAME,
[PSCredential]$Credential,
[switch]$AsObject,
[string]$ExportPath
)
process
{
foreach ($computer in $ComputerName)
{
try
{
$params = @{ ComputerName = $computer }
if ($Credential) { $params.Credential = $Credential }
# Get basic DNS info
$service = Get-Service -Name DNS @params -ErrorAction Stop
$zones = Get-DnsServerZone @params -ErrorAction SilentlyContinue
$forwarders = (Get-DnsServerForwarder @params -ErrorAction SilentlyContinue).IPAddress
$netConfig = Get-CimInstance -ClassName Win32_NetworkAdapterConfiguration @params -Filter "IPEnabled=True" -ErrorAction SilentlyContinue
# Build zone info with counts
$zoneInfo = @()
foreach ($zone in $zones)
{
if ($zone.ZoneName -ne 'TrustAnchors')
{
$recordCount = (Get-DnsServerResourceRecord -ZoneName $zone.ZoneName @params -ErrorAction SilentlyContinue | Measure-Object).Count
$zoneInfo += [PSCustomObject]@{
ZoneName = $zone.ZoneName
ZoneType = $zone.ZoneType
DynamicUpdate = $zone.DynamicUpdate
RecordCount = $recordCount
IsReverse = $zone.IsReverseLookupZone
}
}
}
# Create result object
$result = [PSCustomObject]@{
ComputerName = $computer
ServiceStatus = $service.Status
ForwardZones = ($zoneInfo | Where-Object { -not $_.IsReverse }).Count
ReverseZones = ($zoneInfo | Where-Object { $_.IsReverse }).Count
TotalZones = $zoneInfo.Count
Zones = $zoneInfo
Forwarders = $forwarders
NetworkAdapters = $netConfig | Select-Object Description, @{N = 'IP'; E = { $_.IPAddress -join ',' } }, @{N = 'DNS'; E = { $_.DNSServerSearchOrder -join ',' } }
Status = 'Success'
}
# Export if requested
if ($ExportPath)
{
$timestamp = Get-Date -Format 'yyyyMMdd_HHmmss'
$filename = "$ExportPath\DNS_$computer`_$timestamp.json"
$result | ConvertTo-Json -Depth 5 | Out-File $filename -Encoding UTF8
Write-Host "Exported to: $filename" -ForegroundColor Green
}
# Return object or display formatted output
if ($AsObject)
{
Write-Output $result
}
else
{
# Display clean formatted output
Write-Host "`nDNS SERVER: $computer" -ForegroundColor Cyan
Write-Host "Service Status: " -NoNewline
$color = if ($result.ServiceStatus -eq 'Running') { 'Green' } else { 'Red' }
Write-Host $result.ServiceStatus -ForegroundColor $color
Write-Host "`nZONE SUMMARY:" -ForegroundColor Yellow
Write-Host " Forward Zones: $($result.ForwardZones)"
Write-Host " Reverse Zones: $($result.ReverseZones)"
Write-Host " Total Zones: $($result.TotalZones)"
if ($result.Zones)
{
Write-Host "`nZONE DETAILS:" -ForegroundColor Yellow
$result.Zones | Format-Table ZoneName, ZoneType, DynamicUpdate, RecordCount -AutoSize
}
if ($result.Forwarders)
{
Write-Host "`nFORWARDERS:" -ForegroundColor Yellow
$result.Forwarders | ForEach-Object { Write-Host " $_" }
}
if ($result.NetworkAdapters)
{
Write-Host "`nNETWORK CONFIG:" -ForegroundColor Yellow
$result.NetworkAdapters | Format-Table Description, IP, DNS -AutoSize
}
Write-Host ""
}
}
catch
{
if ($AsObject)
{
[PSCustomObject]@{
ComputerName = $computer
Status = 'Failed'
Error = $_.Exception.Message
}
}
else
{
Write-Host "`nDNS SERVER: $computer" -ForegroundColor Red
Write-Host "Status: Failed" -ForegroundColor Red
Write-Host "Error: $($_.Exception.Message)" -ForegroundColor Red
}