debug unc qualifier

This commit is contained in:
duffyduck 2026-01-07 15:29:08 +01:00
parent 479b365ebb
commit 5bb00b63e5
1 changed files with 11 additions and 6 deletions

View File

@ -25,12 +25,17 @@ function Get-Config {
function Get-UNCPath { function Get-UNCPath {
param([string]$LocalPath) param([string]$LocalPath)
# Wenn der Pfad bereits ein UNC-Pfad ist, direkt zurueckgeben
if ($LocalPath -match '^\\\\') {
return $LocalPath
}
$drive = Split-Path -Path $LocalPath -Qualifier $drive = Split-Path -Path $LocalPath -Qualifier
$driveLetter = $drive.TrimEnd(':') $driveLetter = $drive.TrimEnd(':')
$netUse = net use 2>$null | Where-Object { $_ -match "^\s*\w*\s+$driveLetter`:" } $netUse = net use 2>$null | Where-Object { $_ -match "^\s*\w*\s+$driveLetter`:" }
if ($netUse) { if ($netUse) {
$parts = $netUse -split '\s+' $parts = $netUse -split '\s+'
foreach ($part in $parts) { foreach ($part in $parts) {
@ -41,19 +46,19 @@ function Get-UNCPath {
} }
} }
} }
$psDrive = Get-PSDrive -Name $driveLetter -ErrorAction SilentlyContinue $psDrive = Get-PSDrive -Name $driveLetter -ErrorAction SilentlyContinue
if ($psDrive -and $psDrive.DisplayRoot) { if ($psDrive -and $psDrive.DisplayRoot) {
$relativePath = $LocalPath.Substring($drive.Length) $relativePath = $LocalPath.Substring($drive.Length)
return Join-Path $psDrive.DisplayRoot $relativePath return Join-Path $psDrive.DisplayRoot $relativePath
} }
$wmiDrive = Get-WmiObject -Class Win32_LogicalDisk -Filter "DeviceID='$drive'" -ErrorAction SilentlyContinue $wmiDrive = Get-WmiObject -Class Win32_LogicalDisk -Filter "DeviceID='$drive'" -ErrorAction SilentlyContinue
if ($wmiDrive -and $wmiDrive.ProviderName) { if ($wmiDrive -and $wmiDrive.ProviderName) {
$relativePath = $LocalPath.Substring($drive.Length) $relativePath = $LocalPath.Substring($drive.Length)
return Join-Path $wmiDrive.ProviderName $relativePath return Join-Path $wmiDrive.ProviderName $relativePath
} }
$computerName = $env:COMPUTERNAME $computerName = $env:COMPUTERNAME
$adminShare = "\\$computerName\$driveLetter`$" $adminShare = "\\$computerName\$driveLetter`$"
$relativePath = $LocalPath.Substring($drive.Length) $relativePath = $LocalPath.Substring($drive.Length)