title: PowerShell : How can I set a variable from a single column in multi-column output?
body: <p>I am using <code>Get-PhysicalDisk | Format-Table DeviceID, UniqueID</code> to get a listing of drive number and serial number of all drives on a Windows 2016 Server.  I want to search for one serial number and capture only the drive number as a variable.  I'm used to awk in UNIX and I'm totally stumped on how to achieve this in PowerShell.</p>
  
  <pre><code>Get-PhysicalDisk | Format-Table DeviceID, UniqueID
  
  DeviceID UniqueID                              
  -------- --------                              
  5        624A937024897B4FF488CBF800027A4B      
  8        624A937024897B4FF488CBF800028A4D      
  7        624A937024897B4FF488CBF800027A59      
  0        {c4d394f5-509e-11e9-a834-806e6f6e6963}
  1        {c4d394f6-509e-11e9-a834-806e6f6e6963}
  2        {c4d394f7-509e-11e9-a834-806e6f6e6963}
  3        {c4d394f8-509e-11e9-a834-806e6f6e6963}
  4        {c4d394f9-509e-11e9-a834-806e6f6e6963}
  6        624A937024897B4FF488CBF800027A56
  </code></pre>
  
  <p>I want to expand this command to find SerialNumber <code>624A937024897B4FF488CBF800027A56</code> then set a variable called <code>$DriveNumber</code> to the value of <code>6</code> as shown in the output.  </p>
  
  <p>I then plan to use this variable in <code>Set-Disk</code> to take the drive offline/online as a perform a volume overwrite.  I don't want to hard code the drive number because upon reboot, the drive number could change.<br>
  <em>NOTE</em> I was using <code>Get-Disk</code> and piping the appropriate output to <code>Set-Disk</code> to perform my drive off/online.  But, I have a mysterious issue of the virtual drives not displaying with <code>Get-Disk</code>, therefore I'm trying to find a workaround with <code>Get-PhysicalDisk</code> Thanks!</p>