Skip to content

Instantly share code, notes, and snippets.

@GongT
Created November 4, 2020 17:21
Show Gist options
  • Save GongT/fbe40710875249c4d0256fccd92bcc9d to your computer and use it in GitHub Desktop.
Save GongT/fbe40710875249c4d0256fccd92bcc9d to your computer and use it in GitHub Desktop.
Sync network drive mapping when run "PowerShell (admin)"
### append this into $PROFILE.CurrentUserAllHosts
foreach ($info in Get-ChildItem -Path HKCU:/Network) {
$letter = Split-Path -Leaf -Path $info.Name -ErrorAction SilentlyContinue
if (-Not $letter) { continue }
if (Test-Path -Path "${letter}:/") { continue }
$remote = $info.GetValue('RemotePath')
if (-Not $remote) { continue }
New-PSDrive -Scope Global -PSProvider "FileSystem" -Name $letter -Root $remote -ErrorAction SilentlyContinue | Out-Null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment