title: powershell and diskpart
body: <p>In short I have a volume that I need to assign a drive letter to (using diskpart). The problem now comes in that the volume does not remain the same. You enter disk part a do a "list volume" and the specific volume would be volume 0, then "exit". Enter again and the do a "list volume" again and this time it is volume 4. And so it continues. 
  Now if this was done by a person it would not be an issue, however this is an automated task, that will "disconnect" the volume on windows 2003 and used on other servers and mounted again on the windows 2003 server.</p>
  
  <p>I'm trying to write a script in powershell that will be able to identify the volume based on a few unique field(s). The problem comes in that I'm getting stuck on interpreting the output of diskpart's "list volume" command with powershell.</p>
  
  <p>The following command provides the output that I need to work with but there after I'm lost.</p>
  
  <pre><code>cls
  $dp = "list volume" | diskpart | ? { $_ -match "^  [^-]" }
  $dp | format-table  -auto
  </code></pre>
  
  <p>and this is the output it provides and the volume that I'm looking for is Volume 1.</p>
  
  <pre><code>  Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
    Volume 0     F                       DVD-ROM         0 B  Healthy            
    *Volume 1                             Partition    100 GB  Healthy*            
    Volume 2     E   DATA         NTFS   Partition    547 GB  Healthy            
    Volume 3     C   OS           NTFS   Partition     39 GB  Healthy    System  
    Volume 4     D   APPS         NTFS   Partition     98 GB  Healthy            
  </code></pre>
  
  <p>Can anybody help me in the right direction here please. I'm at my tether's end.</p>