dialogcheckbox hinzugefügt um ganzen pfad reinzupacken
This commit is contained in:
parent
4fae56fccb
commit
c369ee18e7
|
|
@ -128,7 +128,7 @@ function Show-UserSelectionDialog {
|
||||||
|
|
||||||
$form = New-Object System.Windows.Forms.Form
|
$form = New-Object System.Windows.Forms.Form
|
||||||
$form.Text = "Benutzer ausw$([char]0x00E4)hlen - Freigabe"
|
$form.Text = "Benutzer ausw$([char]0x00E4)hlen - Freigabe"
|
||||||
$form.Size = New-Object System.Drawing.Size(450, 500)
|
$form.Size = New-Object System.Drawing.Size(450, 530)
|
||||||
$form.StartPosition = "CenterScreen"
|
$form.StartPosition = "CenterScreen"
|
||||||
$form.FormBorderStyle = "FixedDialog"
|
$form.FormBorderStyle = "FixedDialog"
|
||||||
$form.MaximizeBox = $false
|
$form.MaximizeBox = $false
|
||||||
|
|
@ -146,7 +146,7 @@ function Show-UserSelectionDialog {
|
||||||
|
|
||||||
$listBox = New-Object System.Windows.Forms.ListBox
|
$listBox = New-Object System.Windows.Forms.ListBox
|
||||||
$listBox.Location = New-Object System.Drawing.Point(10, 45)
|
$listBox.Location = New-Object System.Drawing.Point(10, 45)
|
||||||
$listBox.Size = New-Object System.Drawing.Size(410, 360)
|
$listBox.Size = New-Object System.Drawing.Size(410, 330)
|
||||||
$listBox.Font = New-Object System.Drawing.Font("Segoe UI", 10)
|
$listBox.Font = New-Object System.Drawing.Font("Segoe UI", 10)
|
||||||
$form.Controls.Add($listBox)
|
$form.Controls.Add($listBox)
|
||||||
|
|
||||||
|
|
@ -166,9 +166,24 @@ function Show-UserSelectionDialog {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
$chkFullPath = New-Object System.Windows.Forms.CheckBox
|
||||||
|
$chkFullPath.Text = "Kompletten Pfad in Verkn$([char]0x00FC)pfungsname schreiben"
|
||||||
|
$chkFullPath.Location = New-Object System.Drawing.Point(10, 385)
|
||||||
|
$chkFullPath.Size = New-Object System.Drawing.Size(410, 25)
|
||||||
|
$chkFullPath.Font = New-Object System.Drawing.Font("Segoe UI", 9)
|
||||||
|
$form.Controls.Add($chkFullPath)
|
||||||
|
|
||||||
|
$lblExample = New-Object System.Windows.Forms.Label
|
||||||
|
$lblExample.Text = "(z.B. 'Mandanten - S - Schmidt - Lohn' statt nur 'Lohn')"
|
||||||
|
$lblExample.Location = New-Object System.Drawing.Point(27, 408)
|
||||||
|
$lblExample.Size = New-Object System.Drawing.Size(400, 20)
|
||||||
|
$lblExample.ForeColor = [System.Drawing.Color]::Gray
|
||||||
|
$lblExample.Font = New-Object System.Drawing.Font("Segoe UI", 8)
|
||||||
|
$form.Controls.Add($lblExample)
|
||||||
|
|
||||||
$okBtn = New-Object System.Windows.Forms.Button
|
$okBtn = New-Object System.Windows.Forms.Button
|
||||||
$okBtn.Text = "Freigeben"
|
$okBtn.Text = "Freigeben"
|
||||||
$okBtn.Location = New-Object System.Drawing.Point(240, 420)
|
$okBtn.Location = New-Object System.Drawing.Point(240, 450)
|
||||||
$okBtn.Size = New-Object System.Drawing.Size(85, 30)
|
$okBtn.Size = New-Object System.Drawing.Size(85, 30)
|
||||||
$okBtn.Enabled = $false
|
$okBtn.Enabled = $false
|
||||||
$okBtn.DialogResult = [System.Windows.Forms.DialogResult]::OK
|
$okBtn.DialogResult = [System.Windows.Forms.DialogResult]::OK
|
||||||
|
|
@ -177,7 +192,7 @@ function Show-UserSelectionDialog {
|
||||||
|
|
||||||
$cancelBtn = New-Object System.Windows.Forms.Button
|
$cancelBtn = New-Object System.Windows.Forms.Button
|
||||||
$cancelBtn.Text = "Abbrechen"
|
$cancelBtn.Text = "Abbrechen"
|
||||||
$cancelBtn.Location = New-Object System.Drawing.Point(335, 420)
|
$cancelBtn.Location = New-Object System.Drawing.Point(335, 450)
|
||||||
$cancelBtn.Size = New-Object System.Drawing.Size(85, 30)
|
$cancelBtn.Size = New-Object System.Drawing.Size(85, 30)
|
||||||
$cancelBtn.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
|
$cancelBtn.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
|
||||||
$form.CancelButton = $cancelBtn
|
$form.CancelButton = $cancelBtn
|
||||||
|
|
@ -195,13 +210,18 @@ function Show-UserSelectionDialog {
|
||||||
})
|
})
|
||||||
|
|
||||||
$script:selectedUser = $null
|
$script:selectedUser = $null
|
||||||
|
$script:useFullPath = $false
|
||||||
|
|
||||||
if ($form.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK -and $listBox.SelectedIndex -ge 0) {
|
if ($form.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK -and $listBox.SelectedIndex -ge 0) {
|
||||||
$selectedText = $listBox.SelectedItem
|
$selectedText = $listBox.SelectedItem
|
||||||
$script:selectedUser = $script:allUsers | Where-Object { $_.FullName -eq $selectedText } | Select-Object -First 1
|
$script:selectedUser = $script:allUsers | Where-Object { $_.FullName -eq $selectedText } | Select-Object -First 1
|
||||||
|
$script:useFullPath = $chkFullPath.Checked
|
||||||
}
|
}
|
||||||
|
|
||||||
return $script:selectedUser
|
return @{
|
||||||
|
User = $script:selectedUser
|
||||||
|
UseFullPath = $script:useFullPath
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Add-FreigabePermission {
|
function Add-FreigabePermission {
|
||||||
|
|
@ -290,34 +310,50 @@ try {
|
||||||
throw "Keine Benutzer gefunden!"
|
throw "Keine Benutzer gefunden!"
|
||||||
}
|
}
|
||||||
|
|
||||||
$selectedUser = Show-UserSelectionDialog -Users $users
|
$dialogResult = Show-UserSelectionDialog -Users $users
|
||||||
if (-not $selectedUser) {
|
if (-not $dialogResult.User) {
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$selectedUser = $dialogResult.User
|
||||||
|
$useFullPath = $dialogResult.UseFullPath
|
||||||
|
|
||||||
$userName = $selectedUser.SamAccountName
|
$userName = $selectedUser.SamAccountName
|
||||||
$userFolder = Join-Path $basePath $userName
|
$userFolder = Join-Path $basePath $userName
|
||||||
|
|
||||||
if (-not (Test-Path $userFolder)) {
|
if (-not (Test-Path $userFolder)) {
|
||||||
New-Item -Path $userFolder -ItemType Directory -Force | Out-Null
|
New-Item -Path $userFolder -ItemType Directory -Force | Out-Null
|
||||||
}
|
}
|
||||||
|
|
||||||
$uncPath = Get-UNCPath -LocalPath $Path
|
$uncPath = Get-UNCPath -LocalPath $Path
|
||||||
$itemName = Split-Path -Path $Path -Leaf
|
|
||||||
|
# Verknuepfungsname erstellen
|
||||||
|
if ($useFullPath) {
|
||||||
|
# Kompletten Pfad verwenden: \\server\Mandanten\S\Schmidt\Lohn -> Mandanten - S - Schmidt - Lohn
|
||||||
|
$pathForName = $uncPath
|
||||||
|
# UNC-Prefix und Servernamen entfernen
|
||||||
|
if ($pathForName -match '^\\\\[^\\]+\\(.+)$') {
|
||||||
|
$pathForName = $Matches[1]
|
||||||
|
}
|
||||||
|
# Backslashes durch " - " ersetzen
|
||||||
|
$itemName = $pathForName -replace '\\', ' - '
|
||||||
|
} else {
|
||||||
|
$itemName = Split-Path -Path $Path -Leaf
|
||||||
|
}
|
||||||
|
|
||||||
$shortcutPath = Join-Path $userFolder "$itemName.lnk"
|
$shortcutPath = Join-Path $userFolder "$itemName.lnk"
|
||||||
|
|
||||||
$counter = 1
|
$counter = 1
|
||||||
while (Test-Path $shortcutPath) {
|
while (Test-Path $shortcutPath) {
|
||||||
$baseName = [System.IO.Path]::GetFileNameWithoutExtension($itemName)
|
$baseName = $itemName
|
||||||
$extension = [System.IO.Path]::GetExtension($itemName)
|
$shortcutPath = Join-Path $userFolder "$baseName ($counter).lnk"
|
||||||
$shortcutPath = Join-Path $userFolder "$baseName ($counter)$extension.lnk"
|
|
||||||
$counter++
|
$counter++
|
||||||
}
|
}
|
||||||
|
|
||||||
Create-Shortcut -TargetPath $uncPath -ShortcutPath $shortcutPath
|
Create-Shortcut -TargetPath $uncPath -ShortcutPath $shortcutPath
|
||||||
Add-FreigabePermission -TargetPath $Path -QualifiedUserName $selectedUser.QualifiedName
|
Add-FreigabePermission -TargetPath $Path -QualifiedUserName $selectedUser.QualifiedName
|
||||||
Save-FreigabeInfo -TargetPath $Path -UserName $selectedUser.QualifiedName
|
Save-FreigabeInfo -TargetPath $Path -UserName $selectedUser.QualifiedName
|
||||||
|
|
||||||
[System.Windows.Forms.MessageBox]::Show(
|
[System.Windows.Forms.MessageBox]::Show(
|
||||||
"Freigabe erfolgreich erstellt!`n`nBenutzer: $($selectedUser.DisplayName)`nVerkn$([char]0x00FC)pfung: $shortcutPath`nUNC-Pfad: $uncPath",
|
"Freigabe erfolgreich erstellt!`n`nBenutzer: $($selectedUser.DisplayName)`nVerkn$([char]0x00FC)pfung: $shortcutPath`nUNC-Pfad: $uncPath",
|
||||||
"Freigabe erfolgreich",
|
"Freigabe erfolgreich",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue