title: Get only the drive letter from a path in PowerShell
body: <p>I want to make a script in PowerShell to help easily translate a path like this:</p>
  
  <pre><code>H:\MyDoc.docx
  </code></pre>
  
  <p>Into its true absolute path, like this:</p>
  
  <pre><code>\\FileServer\UserShares\Organization\Department\Me\MyDoc.docx
  </code></pre>
  
  <p>In this case, I've created a network drive mapping on my local computer that points <code>H:\</code> to <code>\\FileServer\UserShares\Organization\Department\Me\</code>, but I need to easily expand the mapped path in order to share it with other users who may not have the drive mapping.</p>
  
  <p>Getting the path for the drive is easy.</p>
  
  <pre><code>(Get-PSDrive H).DisplayRoot
  </code></pre>
  
  <p>However, I encounter a problem when I try write a more generic script that can automatically adapt to paths which might point to other mapped drives (I do have several). What I'm having a hard time figuring out is how to extract just the drive letter from a given path.</p>
  
  <p>I thought <code>Split-Path</code> would help, but it appears to only be able to pull the path apart in chunks - the "Parent" and the "Leaf" - neither of which will give only the drive letter.</p>
  
  <p>Is there a way to get <em>just</em> the drive letter from a given path in PowerShell?</p>
  
  <p>Note: I need this to work for paths that point to files <em>or</em> folders.</p>