Update
This commit is contained in:
@@ -19,6 +19,8 @@ function Initialize-Configuration {
|
||||
$script:LinuxLauncher = 'RunNdTrackLinuxUnix_Local.sh'
|
||||
$script:Ergebnisordner = 'C:\SCAN\RESULTS'
|
||||
$script:LogFolder = 'C:\SCAN\SCRIPT\Logs'
|
||||
$script:TargetDomain = '' # Leer = DNS-Domaene des angemeldeten Benutzers
|
||||
$script:DomainController = '' # Optional: FQDN eines DCs der Zieldomaene
|
||||
$script:TestServers = @() # Zum Test z.B. @('GARRDSV003'); leer = AD/RDS
|
||||
$script:RDSConnectionBroker = '' # Leer: wird bei Option 8 abgefragt
|
||||
# Option 8 verwendet einen VOLLSTAENDIGEN, auf den RDS-Servern erreichbaren CMD-Pfad.
|
||||
@@ -47,24 +49,67 @@ function Assert-ServerName {
|
||||
throw "Ungueltiger Servername: $Name (DNS-Name oder IPv4 verwenden)."
|
||||
}
|
||||
}
|
||||
function Get-DirectoryEndpoint {
|
||||
# Keine kundenspezifischen Domain-DNs oder Servernamen.
|
||||
if ($script:DomainController) {
|
||||
Assert-ServerName $script:DomainController
|
||||
return $script:DomainController
|
||||
}
|
||||
if ($script:TargetDomain) {
|
||||
Assert-ServerName $script:TargetDomain
|
||||
return $script:TargetDomain
|
||||
}
|
||||
if ($env:USERDNSDOMAIN) {
|
||||
Assert-ServerName $env:USERDNSDOMAIN
|
||||
return $env:USERDNSDOMAIN
|
||||
}
|
||||
throw 'Keine Benutzerdomaene ermittelbar. TargetDomain oder DomainController konfigurieren oder TestServers mit expliziten Zielservern fuellen.'
|
||||
}
|
||||
function GetADServer {
|
||||
if ($script:TestServers.Count) { return $script:TestServers }
|
||||
$root = [ADSI]'LDAP://RootDSE'
|
||||
$entry = New-Object System.DirectoryServices.DirectoryEntry("LDAP://$($root.defaultNamingContext)")
|
||||
$searcher = New-Object System.DirectoryServices.DirectorySearcher($entry)
|
||||
$results = $null
|
||||
if ($script:TestServers.Count) {
|
||||
foreach ($server in $script:TestServers) { Assert-ServerName $server }
|
||||
return $script:TestServers | Sort-Object -Unique
|
||||
}
|
||||
$endpoint = Get-DirectoryEndpoint
|
||||
$root = $null; $entry = $null; $searcher = $null; $results = $null
|
||||
try {
|
||||
$root = New-Object System.DirectoryServices.DirectoryEntry("LDAP://$endpoint/RootDSE")
|
||||
$namingContext = [string]$root.Properties['defaultNamingContext'].Value
|
||||
$dc = [string]$root.Properties['dnsHostName'].Value
|
||||
if (-not $namingContext -or -not $dc) { throw 'RootDSE liefert keine AD-Domaene bzw. keinen DC.' }
|
||||
Assert-ServerName $dc
|
||||
# Optionalen DC auf Zugehoerigkeit zur expliziten Zieldomaene pruefen.
|
||||
if ($script:TargetDomain) {
|
||||
Assert-ServerName $script:TargetDomain
|
||||
$expected = ($script:TargetDomain.TrimEnd('.').Split('.') | ForEach-Object { 'DC=' + $_ }) -join ','
|
||||
if ($namingContext -ine $expected) { throw "DC gehoert zu $namingContext, erwartet wurde $expected." }
|
||||
}
|
||||
Write-Host "AD-AUSWAHL: $namingContext ueber $dc (aktuelles Windows-Konto)."
|
||||
$entry = New-Object System.DirectoryServices.DirectoryEntry("LDAP://$dc/$namingContext")
|
||||
$searcher = New-Object System.DirectoryServices.DirectorySearcher($entry)
|
||||
$searcher.Filter = '(&(objectCategory=computer)(operatingSystem=*Server*)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))'
|
||||
$searcher.PageSize = 1000
|
||||
[void]$searcher.PropertiesToLoad.Add('dnshostname')
|
||||
[void]$searcher.PropertiesToLoad.Add('name')
|
||||
$results = $searcher.FindAll()
|
||||
@($results | ForEach-Object {
|
||||
if ($_.Properties['dnshostname'].Count) { [string]$_.Properties['dnshostname'][0] }
|
||||
else { [string]$_.Properties['name'][0] }
|
||||
}) | Sort-Object -Unique
|
||||
$servers = @($results | ForEach-Object {
|
||||
if ($_.Properties['dnshostname'].Count) {
|
||||
$name = [string]$_.Properties['dnshostname'][0]
|
||||
Assert-ServerName $name
|
||||
$name
|
||||
} else {
|
||||
Write-Warning "AD-Computer $($_.Properties['name'][0]) ohne DNS-Hostnamen wird uebersprungen."
|
||||
}
|
||||
} | Sort-Object -Unique)
|
||||
if (-not $servers.Count) { throw 'Keine aktivierten Windows-Server mit DNS-Hostnamen gefunden.' }
|
||||
$servers
|
||||
}
|
||||
catch { throw "AD-Abfrage fuer '$endpoint' fehlgeschlagen: $($_.Exception.Message)" }
|
||||
finally {
|
||||
if ($null -ne $results) { $results.Dispose() }
|
||||
$searcher.Dispose(); $entry.Dispose(); $root.Dispose()
|
||||
if ($null -ne $searcher) { $searcher.Dispose() }
|
||||
if ($null -ne $entry) { $entry.Dispose() }
|
||||
if ($null -ne $root) { $root.Dispose() }
|
||||
}
|
||||
}
|
||||
function GetRDSServer {
|
||||
|
||||
Reference in New Issue
Block a user