policie change
This commit is contained in:
@@ -1,16 +1,17 @@
|
||||
# ============================================================
|
||||
# ByteTrail GmbH – GPO & File Server Setup Script
|
||||
# Domäne: bytetrail.local
|
||||
# Ausführen auf: SRV-DC01 (bzw. Fileserver) als Domain Admin
|
||||
# Domäne: byte.trail
|
||||
# Ausführen auf: SRV-DC01 als Domain Admin
|
||||
# ============================================================
|
||||
|
||||
Import-Module GroupPolicy -ErrorAction Stop
|
||||
|
||||
#region KONFIGURATION
|
||||
$Domain = "byte.trail"
|
||||
$NetBIOSDom = "BYTE" # NetBIOS Name für Rechtevergabe
|
||||
$NetBIOSDom = "BYTE"
|
||||
$DomainDN = "DC=byte,DC=trail"
|
||||
$FreigabePfad = "E:\Freigabe"
|
||||
$BaselineBackupPath = "C:\Users\Administrator\dms\Baselines"
|
||||
#endregion
|
||||
|
||||
Write-Host "`n=== ByteTrail GPO & Fileserver Setup gestartet ===" -ForegroundColor Cyan
|
||||
@@ -18,23 +19,38 @@ Write-Host "`n=== ByteTrail GPO & Fileserver Setup gestartet ===" -ForegroundCol
|
||||
# ============================================================
|
||||
# TEIL 1: GRUPPENRICHTLINIEN (GPOs)
|
||||
# ============================================================
|
||||
Write-Host "`n[1/2] Konfiguriere Gruppenrichtlinien (GPOs)..." -ForegroundColor Yellow
|
||||
Write-Host "`n[1/3] Konfiguriere Gruppenrichtlinien (GPOs)..." -ForegroundColor Yellow
|
||||
|
||||
# --- 1.1 Microsoft Security Baselines ---
|
||||
Write-Host " [~] Prüfe auf Microsoft Security Baselines..." -ForegroundColor Gray
|
||||
if (Test-Path $BaselineBackupPath) {
|
||||
try {
|
||||
$BaselineGpoName = "MSFT_Windows_Server_2022_Baseline"
|
||||
Write-Host " [~] Importiere Baselines aus $BaselineBackupPath..." -ForegroundColor Gray
|
||||
Import-GPO -BackupGpoName "MSFT Windows Server 2022 - Domain" -Path $BaselineBackupPath -TargetName $BaselineGpoName -CreateIfNeeded -ErrorAction Stop | Out-Null
|
||||
New-GPLink -Name $BaselineGpoName -Target $DomainDN -LinkEnabled Yes | Out-Null
|
||||
Write-Host " [+] Security Baselines erfolgreich importiert und verknüpft." -ForegroundColor Green
|
||||
} catch {
|
||||
Write-Host " [!] Fehler beim Importieren der Baselines: $($_.Exception.Message)" -ForegroundColor Red
|
||||
}
|
||||
} else {
|
||||
Write-Host " [i] MS-Baseline Ordner '$BaselineBackupPath' nicht gefunden." -ForegroundColor Yellow
|
||||
Write-Host " [i] Überspringe Auto-Import. Bitte die Security Baselines später manuell importieren." -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
# --- 1.2 Basis-Sicherheit (Unternehmensspezifisch) ---
|
||||
$GpoSecurityName = "ByteTrail_Base_Security"
|
||||
$GpoDrivesName = "ByteTrail_Mapped_Drives"
|
||||
|
||||
# 1.1 Basis-Sicherheit (Domänenweit)
|
||||
if (!(Get-GPO -Name $GpoSecurityName -ErrorAction SilentlyContinue)) {
|
||||
try {
|
||||
$gpoSec = New-GPO -Name $GpoSecurityName -Comment "Basis-Sicherheitsrichtlinien (Bildschirmsperre etc.)"
|
||||
$gpoSec = New-GPO -Name $GpoSecurityName -Comment "Ergänzende Sicherheitsrichtlinien (Bildschirmsperre etc.)"
|
||||
New-GPLink -Name $GpoSecurityName -Target $DomainDN -LinkEnabled Yes | Out-Null
|
||||
|
||||
# ECHTE RICHTLINIEN SETZEN: Automatische Bildschirmsperre nach 15 Minuten (900 Sekunden) erzwingen
|
||||
# Automatische Bildschirmsperre nach 15 Minuten (900 Sekunden) erzwingen
|
||||
Set-GPRegistryValue -Name $GpoSecurityName -Key "HKCU\Software\Policies\Microsoft\Windows\Control Panel\Desktop" -ValueName "ScreenSaveActive" -Type String -Value "1" | Out-Null
|
||||
Set-GPRegistryValue -Name $GpoSecurityName -Key "HKCU\Software\Policies\Microsoft\Windows\Control Panel\Desktop" -ValueName "ScreenSaverIsSecure" -Type String -Value "1" | Out-Null
|
||||
Set-GPRegistryValue -Name $GpoSecurityName -Key "HKCU\Software\Policies\Microsoft\Windows\Control Panel\Desktop" -ValueName "ScreenSaveTimeOut" -Type String -Value "900" | Out-Null
|
||||
|
||||
Write-Host " [+] GPO '$GpoSecurityName' erstellt, konfiguriert und mit Domäne verknüpft." -ForegroundColor Green
|
||||
Write-Host " [+] Eigene GPO '$GpoSecurityName' (15min Sperre) erstellt und verknüpft." -ForegroundColor Green
|
||||
} catch {
|
||||
Write-Host " [!] Fehler bei GPO '$GpoSecurityName': $($_.Exception.Message)" -ForegroundColor Red
|
||||
}
|
||||
@@ -42,12 +58,12 @@ if (!(Get-GPO -Name $GpoSecurityName -ErrorAction SilentlyContinue)) {
|
||||
Write-Host " [~] GPO '$GpoSecurityName' existiert bereits." -ForegroundColor Gray
|
||||
}
|
||||
|
||||
# 1.2 Netzlaufwerke GPO-Hülle (Verknüpft mit allen relevanten OUs)
|
||||
# --- 1.3 Netzlaufwerke GPO-Hülle ---
|
||||
$GpoDrivesName = "ByteTrail_Mapped_Drives"
|
||||
if (!(Get-GPO -Name $GpoDrivesName -ErrorAction SilentlyContinue)) {
|
||||
try {
|
||||
New-GPO -Name $GpoDrivesName -Comment "Automatische Netzlaufwerk-Zuweisungen fuer Fachabteilungen" | Out-Null
|
||||
|
||||
# Mit den OUs aus Skript 1 verknüpfen
|
||||
New-GPLink -Name $GpoDrivesName -Target "OU=Geschaeftsfuehrung,$DomainDN" -LinkEnabled Yes | Out-Null
|
||||
New-GPLink -Name $GpoDrivesName -Target "OU=Sales,$DomainDN" -LinkEnabled Yes | Out-Null
|
||||
New-GPLink -Name $GpoDrivesName -Target "OU=Marketing,$DomainDN" -LinkEnabled Yes | Out-Null
|
||||
@@ -64,9 +80,8 @@ if (!(Get-GPO -Name $GpoDrivesName -ErrorAction SilentlyContinue)) {
|
||||
# ============================================================
|
||||
# TEIL 2: FILESERVER ORDNER & BERECHTIGUNGEN (NTFS)
|
||||
# ============================================================
|
||||
Write-Host "`n[2/2] Konfiguriere Ordnerstruktur & NTFS-Berechtigungen auf $FreigabePfad..." -ForegroundColor Yellow
|
||||
Write-Host "`n[2/3] Konfiguriere Ordnerstruktur & NTFS-Berechtigungen auf $FreigabePfad..." -ForegroundColor Yellow
|
||||
|
||||
# 2.1 Hauptordner erstellen und Freigabe (SMB) einrichten
|
||||
if (!(Test-Path $FreigabePfad)) {
|
||||
New-Item -Path $FreigabePfad -ItemType Directory -Force | Out-Null
|
||||
}
|
||||
@@ -76,15 +91,18 @@ try {
|
||||
Write-Host " [~] SMB-Freigabe 'Freigabe' existiert bereits." -ForegroundColor Gray
|
||||
} catch {
|
||||
New-SmbShare -Name "Freigabe" -Path $FreigabePfad -FullAccess "$NetBIOSDom\Domain Admins" -ChangeAccess "$NetBIOSDom\Domain Users" | Out-Null
|
||||
Write-Host " [+] SMB-Freigabe 'Freigabe' erstellt." -ForegroundColor Green
|
||||
|
||||
# Aktivierung der Access-Based Enumeration (ABE)
|
||||
Set-SmbShare -Name "Freigabe" -FolderEnumerationMode AccessBased -Force
|
||||
|
||||
Write-Host " [+] SMB-Freigabe 'Freigabe' inkl. Access-Based Enumeration (ABE) erstellt." -ForegroundColor Green
|
||||
}
|
||||
|
||||
# Vererbung am Hauptordner deaktivieren
|
||||
# Vererbung deaktivieren und bestehende Rechte konvertieren
|
||||
$AclBase = Get-Acl $FreigabePfad
|
||||
$AclBase.SetAccessRuleProtection($true, $true)
|
||||
Set-Acl -Path $FreigabePfad -AclObject $AclBase
|
||||
|
||||
# 2.2 Definition der Unterordner und zugehöriger Gruppen
|
||||
$Folders = @(
|
||||
@{ Name = "Geschaeftsfuehrung"; Group = "GRP-GF-VOLLZUGRIFF" }
|
||||
@{ Name = "Sales"; Group = "GRP-SALES-FILES" }
|
||||
@@ -102,31 +120,27 @@ $Allow = [System.Security.AccessControl.AccessControlType]::Allow
|
||||
$RuleAdmin = New-Object System.Security.AccessControl.FileSystemAccessRule("$NetBIOSDom\GRP-ADMINS", $RightsFull, $Inheritance, $Propagation, $Allow)
|
||||
$RuleGFRead = New-Object System.Security.AccessControl.FileSystemAccessRule("$NetBIOSDom\GRP-GF-VOLLZUGRIFF", $RightsRead, $Inheritance, $Propagation, $Allow)
|
||||
|
||||
# 2.3 Abteilungsordner anlegen und Rechte setzen
|
||||
foreach ($Folder in $Folders) {
|
||||
$FolderPath = "$FreigabePfad\$($Folder.Name)"
|
||||
if (!(Test-Path $FolderPath)) { New-Item -Path $FolderPath -ItemType Directory -Force | Out-Null }
|
||||
|
||||
$Acl = Get-Acl -Path $FolderPath
|
||||
$Acl.SetAccessRuleProtection($true, $false) # Entfernt alte vererbte Rechte
|
||||
|
||||
# Admins bekommen Vollzugriff
|
||||
$Acl.SetAccessRuleProtection($true, $false)
|
||||
|
||||
$Acl.AddAccessRule($RuleAdmin)
|
||||
|
||||
# Fachabteilung bekommt Ändern-Rechte
|
||||
|
||||
$RuleDept = New-Object System.Security.AccessControl.FileSystemAccessRule("$NetBIOSDom\$($Folder.Group)", $RightsModify, $Inheritance, $Propagation, $Allow)
|
||||
$Acl.AddAccessRule($RuleDept)
|
||||
|
||||
# GF bekommt Leserechte (außer in ihrem eigenen Ordner)
|
||||
|
||||
if ($Folder.Name -ne "Geschaeftsfuehrung") {
|
||||
$Acl.AddAccessRule($RuleGFRead)
|
||||
}
|
||||
|
||||
|
||||
Set-Acl -Path $FolderPath -AclObject $Acl
|
||||
Write-Host " [+] Rechte für Ordner '$($Folder.Name)' erfolgreich gesetzt." -ForegroundColor Green
|
||||
}
|
||||
|
||||
# 2.4 Öffentlicher Austausch-Ordner (Alle dürfen lesen/schreiben)
|
||||
# --- 2.4 Öffentlicher Austausch-Ordner ---
|
||||
$AustauschPath = "$FreigabePfad\Austausch"
|
||||
if (!(Test-Path $AustauschPath)) { New-Item -Path $AustauschPath -ItemType Directory -Force | Out-Null }
|
||||
$AclAustausch = Get-Acl -Path $AustauschPath
|
||||
@@ -138,16 +152,4 @@ $AclAustausch.AddAccessRule($RuleAdmin)
|
||||
Set-Acl -Path $AustauschPath -AclObject $AclAustausch
|
||||
Write-Host " [+] Rechte für Ordner 'Austausch' erfolgreich gesetzt." -ForegroundColor Green
|
||||
|
||||
# ============================================================
|
||||
# ZUSAMMENFASSUNG
|
||||
# ============================================================
|
||||
Write-Host "`n=== Setup abgeschlossen ===" -ForegroundColor Cyan
|
||||
Write-Host "GPOs:" -ForegroundColor White
|
||||
Write-Host "- Base_Security (mit aktivem Screenlock nach 15min) wurde auf die Domäne angewendet."
|
||||
Write-Host "- Mapped_Drives wurde erstellt und mit den OUs verknüpft."
|
||||
Write-Host "`nFileserver:" -ForegroundColor White
|
||||
Write-Host "- Ordnerstruktur unter $FreigabePfad wurde angelegt und SMB-Freigabe aktiviert."
|
||||
Write-Host "- NTFS-Berechtigungen (Sicherheit) wurden strikt nach dem AGDLP-Prinzip gesetzt."
|
||||
Write-Host "`nHINWEIS ZU NETZLAUFWERKEN:" -ForegroundColor Yellow
|
||||
Write-Host "Um die Laufwerke (z.B. Laufwerk S: für Sales) tatsächlich bei den Nutzern einzublenden, öffne nun 'gpmc.msc' (Gruppenrichtlinienverwaltung), bearbeite die GPO 'ByteTrail_Mapped_Drives' und füge unter Benutzerkonfiguration -> Einstellungen -> Windows-Einstellungen -> Laufwerkzuordnungen die Pfade (z.B. \\SRV-DC01\Freigabe\Sales) hinzu."
|
||||
Write-Host ""
|
||||
Write-Host "`n=== Setup abgeschlossen ===" -ForegroundColor Cyan
|
||||
Reference in New Issue
Block a user