scripts/AD_SMB_RIGHTS.ps1 hinzugefügt
This commit is contained in:
179
scripts/AD_SMB_RIGHTS.ps1
Normal file
179
scripts/AD_SMB_RIGHTS.ps1
Normal file
@@ -0,0 +1,179 @@
|
||||
Add-Type -AssemblyName System.Windows.Forms
|
||||
Import-Module ActiveDirectory
|
||||
|
||||
# Berechtigungen definieren
|
||||
$permissions = @{
|
||||
"RO" = [System.Security.AccessControl.FileSystemRights]::Read
|
||||
"RX" = [System.Security.AccessControl.FileSystemRights]::ReadAndExecute
|
||||
"RW" = [System.Security.AccessControl.FileSystemRights]::Modify
|
||||
"FA" = [System.Security.AccessControl.FileSystemRights]::FullControl
|
||||
}
|
||||
|
||||
# Hauptform erstellen
|
||||
$form = New-Object System.Windows.Forms.Form
|
||||
$form.Text = "Verzeichnis- und OU-Auswahl"
|
||||
$form.Size = New-Object System.Drawing.Size(648, 600)
|
||||
|
||||
# RichTextBox für Debug-Informationen hinzufügen (Breite verkleinert auf 600px)
|
||||
$debugTextBox = New-Object System.Windows.Forms.RichTextBox
|
||||
$debugTextBox.Multiline = $true
|
||||
$debugTextBox.Location = New-Object System.Drawing.Point(10, 380)
|
||||
$debugTextBox.Size = New-Object System.Drawing.Size(610, 150) # Breite angepasst auf 600px
|
||||
$debugTextBox.ScrollBars = 'Vertical'
|
||||
$debugTextBox.ReadOnly = $true
|
||||
$form.Controls.Add($debugTextBox)
|
||||
|
||||
# Liste für neu angelegte DLs
|
||||
$newDLs = @()
|
||||
|
||||
# TreeView für die Ordnerstruktur (links)
|
||||
$folderTreeView = New-Object System.Windows.Forms.TreeView
|
||||
$folderTreeView.Location = New-Object System.Drawing.Point(10, 10)
|
||||
$folderTreeView.Size = New-Object System.Drawing.Size(300, 300) # Höhe und Breite angepasst auf 300px
|
||||
$form.Controls.Add($folderTreeView)
|
||||
|
||||
# TextBox für den Hauptordner (zeigt den Pfad des ausgewählten Ordners)
|
||||
$folderTextBox = New-Object System.Windows.Forms.TextBox
|
||||
$folderTextBox.Location = New-Object System.Drawing.Point(10, 315)
|
||||
$folderTextBox.Size = New-Object System.Drawing.Size(300, 30) # Gleiche Breite wie die TreeView
|
||||
$folderTextBox.ReadOnly = $true
|
||||
$form.Controls.Add($folderTextBox)
|
||||
|
||||
# Button für Ordnerauswahl
|
||||
$folderButton = New-Object System.Windows.Forms.Button
|
||||
$folderButton.Text = "Hauptordner auswählen"
|
||||
$folderButton.Location = New-Object System.Drawing.Point(10, 340)
|
||||
$folderButton.Size = New-Object System.Drawing.Size(300, 30) # Gleiche Breite wie die TextBox
|
||||
$form.Controls.Add($folderButton)
|
||||
|
||||
# Ordnerauswahl-Funktion mit FolderBrowserDialog
|
||||
$folderButton.Add_Click({
|
||||
$folderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog
|
||||
$folderBrowser.Description = "Wählen Sie den Hauptordner aus, in dem die Unterordner liegen"
|
||||
|
||||
if ($folderBrowser.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) {
|
||||
# Zeige den ausgewählten Ordner in der TextBox
|
||||
$folderTextBox.Text = $folderBrowser.SelectedPath
|
||||
$debugTextBox.AppendText("Hauptordner ausgewählt: $($folderTextBox.Text)" + [Environment]::NewLine)
|
||||
|
||||
# Leere die TreeView und lade den Ordnerbaum
|
||||
$folderTreeView.Nodes.Clear()
|
||||
|
||||
# Füge die Wurzel des Ordners als Node hinzu
|
||||
$rootNode = New-Object System.Windows.Forms.TreeNode($folderBrowser.SelectedPath)
|
||||
$rootNode.Tag = $folderBrowser.SelectedPath # Pfad im Tag speichern
|
||||
$folderTreeView.Nodes.Add($rootNode)
|
||||
|
||||
# Lade nur die ersten Unterordner (maximal eine Ebene tief)
|
||||
Load-Subfolders $folderBrowser.SelectedPath $rootNode
|
||||
|
||||
# Expandiere den Root-Node
|
||||
$rootNode.Expand()
|
||||
}
|
||||
})
|
||||
|
||||
# Funktion zum Laden der Unterordner in die TreeView (maximal 1 Ebene tief)
|
||||
function Load-Subfolders {
|
||||
param (
|
||||
[string]$parentFolder,
|
||||
[System.Windows.Forms.TreeNode]$parentNode
|
||||
)
|
||||
|
||||
try {
|
||||
# Überprüfen, ob der Ordner existiert
|
||||
if (Test-Path $parentFolder) {
|
||||
# Hole alle Unterordner des aktuellen Ordners
|
||||
$subfolders = Get-ChildItem -Path $parentFolder -Directory -ErrorAction SilentlyContinue
|
||||
|
||||
foreach ($subfolder in $subfolders) {
|
||||
# Erstelle den Knoten für den Unterordner
|
||||
$node = New-Object System.Windows.Forms.TreeNode($subfolder.Name)
|
||||
$node.Tag = $subfolder.FullName # Pfad des Unterordners im Tag speichern
|
||||
$parentNode.Nodes.Add($node)
|
||||
|
||||
# Prüfe, ob dieser Ordner Unterordner hat (für den "+" Indikator)
|
||||
$hasSubfolders = (Get-ChildItem -Path $subfolder.FullName -Directory -ErrorAction SilentlyContinue).Count -gt 0
|
||||
if ($hasSubfolders) {
|
||||
# Wenn Unterordner vorhanden sind, den Knoten expandierbar machen (zeige +)
|
||||
$node.Nodes.Add([System.Windows.Forms.TreeNode]::new("Dummy")) # Platzhalter hinzufügen
|
||||
}
|
||||
}
|
||||
|
||||
# Expandiere den Node, wenn Unterordner vorhanden sind
|
||||
if ($parentNode.Nodes.Count -gt 0) {
|
||||
$parentNode.Expand()
|
||||
}
|
||||
} else {
|
||||
$debugTextBox.AppendText("Pfad nicht gefunden: $parentFolder" + [Environment]::NewLine)
|
||||
}
|
||||
} catch {
|
||||
$debugTextBox.AppendText("Fehler beim Laden der Ordnerstruktur: $_" + [Environment]::NewLine)
|
||||
}
|
||||
}
|
||||
|
||||
# Abschnitt für OU Auswahl
|
||||
|
||||
# ListBox für OUs (Höhe angepasst auf 300px)
|
||||
$ouListBox = New-Object System.Windows.Forms.ListBox
|
||||
$ouListBox.Location = New-Object System.Drawing.Point(320, 10) # Etwas rechts vom TreeView
|
||||
$ouListBox.Size = New-Object System.Drawing.Size(300, 305) # Gleiche Höhe wie die TreeView
|
||||
$ouListBox.SelectionMode = [System.Windows.Forms.SelectionMode]::MultiExtended
|
||||
$form.Controls.Add($ouListBox)
|
||||
|
||||
# TextBox für die ausgewählte OU
|
||||
$ouTextBox = New-Object System.Windows.Forms.TextBox
|
||||
$ouTextBox.Location = New-Object System.Drawing.Point(320, 315)
|
||||
$ouTextBox.Size = New-Object System.Drawing.Size(300, 30) # Gleiche Breite wie ListBox
|
||||
$ouTextBox.ReadOnly = $true
|
||||
$form.Controls.Add($ouTextBox)
|
||||
|
||||
# Button für OU-Auswahl
|
||||
$ouButton = New-Object System.Windows.Forms.Button
|
||||
$ouButton.Text = "OU auswählen"
|
||||
$ouButton.Location = New-Object System.Drawing.Point(320, 340)
|
||||
$ouButton.Size = New-Object System.Drawing.Size(300, 30) # Gleiche Breite wie TextBox
|
||||
$form.Controls.Add($ouButton)
|
||||
|
||||
# Funktion zum Laden der OUs in die ListBox direkt beim Start
|
||||
function Load-OUs {
|
||||
try {
|
||||
# Alle OUs abrufen und in die ListBox einfügen
|
||||
$ous = Get-ADOrganizationalUnit -Filter * | Select-Object -ExpandProperty DistinguishedName
|
||||
$ouListBox.Items.Clear()
|
||||
$ouListBox.Items.AddRange($ous)
|
||||
$debugTextBox.AppendText("OUs wurden geladen." + [Environment]::NewLine)
|
||||
} catch {
|
||||
$debugTextBox.AppendText("Fehler beim Laden der OUs: $_" + [Environment]::NewLine)
|
||||
}
|
||||
}
|
||||
|
||||
# OUs laden, wenn das Formular geladen wird
|
||||
Load-OUs
|
||||
|
||||
# Event für ListBox: Wenn eine OU ausgewählt wird
|
||||
$ouListBox.Add_SelectedIndexChanged({
|
||||
if ($ouListBox.SelectedItem) {
|
||||
$ouTextBox.Text = $ouListBox.SelectedItem
|
||||
$debugTextBox.AppendText("Ausgewählte OU: $($ouTextBox.Text)" + [Environment]::NewLine)
|
||||
}
|
||||
})
|
||||
|
||||
# Starten Button
|
||||
$startButton = New-Object System.Windows.Forms.Button
|
||||
$startButton.Text = "Starten"
|
||||
$startButton.Location = New-Object System.Drawing.Point(10, 640)
|
||||
$startButton.Size = New-Object System.Drawing.Size(150, 30)
|
||||
$startButton.Add_Click({
|
||||
$mainFolderPath = $folderTextBox.Text
|
||||
$ouPath = $ouTextBox.Text
|
||||
|
||||
if (-not $mainFolderPath) {
|
||||
$debugTextBox.AppendText("Kein Hauptordner ausgewählt." + [Environment]::NewLine)
|
||||
} else {
|
||||
$debugTextBox.AppendText("Hauptordner: $mainFolderPath, OU: $ouPath" + [Environment]::NewLine)
|
||||
# Weiterer Code für die Verarbeitung des Ordners und der OU
|
||||
}
|
||||
})
|
||||
|
||||
# Formular anzeigen
|
||||
$form.ShowDialog()
|
||||
Reference in New Issue
Block a user