Home/ Dee Has A Confession To Make/ Photo 5
5 / 21

Map Drive — Win 11

D Dee Williams N New Sensation
Dee Has A Confession To Make 5
Prev
5 / 21
Next All Photos
win 11 map drive

$driveLetter = "Z:" $sharePath = "\\server\share" $logFile = "$env:TEMP\map_drive.log" function Write-Log Out-File -FilePath $logFile -Append $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

Map Drive — Win 11

$driveLetter = "Z:" $sharePath = "\\server\share" $logFile = "$env:TEMP\map_drive.log" function Write-Log Out-File -FilePath $logFile -Append $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