8383
8484param (
8585 [Parameter (Mandatory )]
86+ [ValidateNotNull ()]
8687 [PSCredential ]$Credential ,
8788
8889 [Parameter (Mandatory )]
90+ [ValidateNotNullOrEmpty ()]
8991 [string []]$NetworkRanges ,
9092
9193 [Parameter (Mandatory )]
92- [ValidateScript ({
93- if (@ ($_ ).Count -eq 0 ) {
94- throw " CommonPorts cannot be empty."
95- }
96- foreach ($port in $_ ) {
97- if ($port -lt 1 -or $port -gt 65535 ) {
98- throw " Invalid port '$port '. Ports must be between 1 and 65535."
99- }
100- }
101- $true
102- })]
94+ [ValidateRange (1 , 65535 )]
10395 [int []]$CommonPorts ,
10496
10597 [Parameter (Mandatory )]
@@ -109,15 +101,19 @@ param(
109101 [bool ]$CheckSMBSigning ,
110102
111103 [Parameter (Mandatory )]
104+ [ValidateNotNullOrEmpty ()]
112105 [string ]$OutputBaseDir ,
113106
114107 [Parameter (Mandatory )]
108+ [ValidateNotNullOrEmpty ()]
115109 [string ]$OutputHostsCsvPath ,
116110
117111 [Parameter (Mandatory )]
112+ [ValidateNotNullOrEmpty ()]
118113 [string ]$OutputOpenPortsCsvPath ,
119114
120115 [Parameter (Mandatory )]
116+ [ValidateNotNullOrEmpty ()]
121117 [string ]$OutputSmbSigningCsvPath
122118)
123119
@@ -138,7 +134,7 @@ Import-Module $helpersModulePath -Force -ErrorAction Stop
138134# ---------------------------------------------------------------------
139135$ScriptStartTime = Get-Date - Format " yyyyMMdd_HHmmss"
140136
141- Write-MSADPTLog - Message " MSADPT_scan_network .ps1 starting." - Level ' INFO'
137+ Write-MSADPTLog - Message " MSADPT_scan_network2 .ps1 starting." - Level ' INFO'
142138Write-MSADPTLog - Message " NetworkRanges : $ ( $NetworkRanges -join ' , ' ) " - Level ' INFO'
143139Write-MSADPTLog - Message " CommonPorts : $ ( $CommonPorts -join ' , ' ) " - Level ' INFO'
144140Write-MSADPTLog - Message " UseNmapIfAvailable : $UseNmapIfAvailable " - Level ' INFO'
@@ -643,7 +639,40 @@ foreach ($Range in $NetworkRanges) {
643639 Write-MSADPTLog - Message " - Method 1/5: Remote Registry via .NET (LanmanServer -> LanmanWorkstation)."
644640
645641 try {
646- $baseKey = [Microsoft.Win32.RegistryKey ]::OpenRemoteBaseKey(
642+ $regCandidates = @ (
643+ @ {
644+ Scope = ' LanmanServer'
645+ Path = ' SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters'
646+ },
647+ @ {
648+ Scope = ' LanmanWorkstation'
649+ Path = ' SYSTEM\CurrentControlSet\Services\LanmanWorkstation\Parameters'
650+ }
651+ )
652+
653+ foreach ($candidate in $regCandidates ) {
654+ $enable = Get-MSADPTRemoteRegistryValue `
655+ - ComputerName $RemoteTarget `
656+ - SubKey $candidate.Path `
657+ - ValueName ' EnableSecuritySignature'
658+
659+ $require = Get-MSADPTRemoteRegistryValue `
660+ - ComputerName $RemoteTarget `
661+ - SubKey $candidate.Path `
662+ - ValueName ' RequireSecuritySignature'
663+
664+ if ($null -ne $enable -or $null -ne $require ) {
665+ $SMBConfig = [PSCustomObject ]@ {
666+ Scope = $candidate.Scope
667+ EnableSecuritySignature = if ($null -ne $enable ) { [int ]$enable } else { $null }
668+ RequireSecuritySignature = if ($null -ne $require ) { [int ]$require } else { $null }
669+ }
670+
671+ $ConfigSource = " Remote Registry ($ ( $candidate.Scope ) )"
672+ break
673+ }
674+ }
675+ <# $baseKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey(
647676 [Microsoft.Win32.RegistryHive]::LocalMachine,
648677 $RemoteTarget
649678 )
@@ -695,7 +724,7 @@ foreach ($Range in $NetworkRanges) {
695724 catch {
696725 Write-MSADPTLog -Message " - Remote Registry failed for $($candidate.Scope): $($_.Exception.Message)" -Level 'WARNING'
697726 }
698- }
727+ } #>
699728 }
700729 catch {
701730 Write-MSADPTLog - Message " - Remote Registry initialization failed on ${RemoteTarget} : $ ( $_.Exception.Message ) " - Level ' WARNING'
@@ -1059,5 +1088,12 @@ foreach ($Range in $NetworkRanges) {
10591088 }
10601089}
10611090
1091+ if (@ ($SMBSigningStatus ).Count -gt 0 ) {
1092+ $SMBSigningStatus | Export-Csv - Path $OutputSmbSigningCsvPath - NoTypeInformation - Force
1093+ Write-Log - Message " SMB signing results written to $OutputSmbSigningCsvPath ." - Level ' INFO'
1094+ }
1095+ else {
1096+ Write-Log - Message " No SMB signing results were collected." - Level ' WARNING'
1097+ }
10621098
1063- Write-MSADPTLog - Message " MSADPT_scan_network .ps1 completed." - Level ' INFO'
1099+ Write-MSADPTLog - Message " MSADPT_scan_network2 .ps1 completed." - Level ' INFO'
0 commit comments