Win 11 Map Drive Verified Info
$driveLetter = "Z:" $sharePath = "\\server\share" $logFile = "$env:TEMP\map_drive.log" function Write-Log param([string]$msg) $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" "$timestamp - $msg" $existing = Get-PSDrive -Name $driveLetter[0] -ErrorAction SilentlyContinue if ($existing -and $existing.DisplayRoot -eq $sharePath) Write-Log "Drive $driveLetter already mapped to $sharePath" exit 0 Remove stale mapping if letter conflict if ($existing) Write-Log "Removing conflicting mapping on $driveLetter" net use $driveLetter /delete /y Map the drive try $cred = Import-Clixml -Path "C:\secrets\share_cred.xml" -ErrorAction Stop New-PSDrive -Name $driveLetter[0] -PSProvider FileSystem ` -Root $sharePath -Persist -Credential $cred -ErrorAction Stop Write-Log "Successfully mapped $driveLetter to $sharePath" catch Write-Log "FAILED: $_" exit 1