title: Convert UNC Path to NTFS local path
body: <p>I have a problem converting UNC location to local drive in powershell. So my code basically takes input from user as read Host as UNC path for a DB Backup location. The location could be like this <code>\\ServerName\m$\SQLBackups\123</code>.</p>
  
  <p>It then prompts where the backup is being copied from. Again this is a UNC path such as <code>\\ServerName\g$\SQLRestores\444\Filename.bak</code>. </p>
  
  <p>I need to convert both paths to their local path so that it reads <code>m:\sqldbackups\123</code> and <code>g:\sqlrestores\444\Filename.bak</code>.</p>
  
  <p>Here is my code below and I have added a comment of what I want the final output to be.</p>
  
  <pre><code>$BackupPath = "\\ServerName\m$\SQLBackups\123"
  $Dumps = Split-Path -Path $BackupPath -Leaf
  $Drive = Split-Path -Path $BackupPath -Parent
  $LastTwo = $Drive.Substring($Drive.get_Length()-2)
  
  
  $FullNTFS = $LastTwo + "\" + $Dumps
  $FullNTFS = $FullNTFS.Replace("$",":")
  $FullNTFS 
  #This should be M:\SQLBACKUPS\123
  
  $RestorePath = "\\ServerName\g$\SQLRestores\444\Filename.bak"
  $Dumps = Split-Path -Path $RestorePath -Leaf
  $Drive = Split-Path -Path $RestorePath -Parent
  $LastTwo = $Drive.Substring($Drive.get_Length()-2)
  
  
  $FullNTFS = $LastTwo + "\" + $Dumps
  $FullNTFS = $FullNTFS.Replace("$",":")
  $FullNTFS 
  #This should be read as g:\sqlrestores\444\FileName.bak
  </code></pre>