title: Get the first node value from xml in sql column using powershell
body: <p>I am trying get the first node value from the xml stored in the sql column. Currently it is displayed all the UniqueID but i want only first one i.e +7f8wMRJgFKWlQqyWwI27yOVc80=</p>
  
  <p><strong>XML</strong> :</p>
  
  <pre><code>&lt;UniqueIDList&gt;
      &lt;UniqueID&gt;+7f8wMRJgFKWlQqyWwI27yOVc80=&lt;/UniqueID&gt;
      &lt;UniqueID&gt;3LZYc365TRSHEUZRwBaaYCPszqQ=&lt;/UniqueID&gt;
      &lt;UniqueID&gt;WnK4aLZKO8kFyi+Ii8s9A2yl/Kg=&lt;/UniqueID&gt;
      &lt;UniqueID&gt;i0UHoU0r2fYBvCrvFbcKkikXgas=&lt;/UniqueID&gt;
  &lt;/UniqueIDList&gt;
  </code></pre>
  
  <p><strong>Powershell Code</strong> :</p>
  
  <pre><code>$connectionString = "Server=tcp:$dataSource.database.windows.net,1433;uid=$user; pwd=$pwd;Database=$database;Persist Security Info=False;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
  
  $con = New-Object System.Data.SqlClient.SqlConnection
  $con.ConnectionString = $connectionString
  $con.Open()
  
  $cmd = New-Object System.Data.SqlClient.SqlCommand
  $cmd.CommandText = "select license from tbllicense order by LicenseID desc"
  $cmd.Connection = $con
  
  $as = New-Object System.Data.SqlClient.SqlDataAdapter
  $ds = New-Object System.Data.DataSet
  $as.SelectCommand = $cmd
  $as.Fill($ds);
  
  $xmlDocs = $ds.Tables[0].Rows[0][0]
  write-host "License Value : " $xmlDocs
  Select-Xml -Content $xmlDocs -XPath "//UniqueID" | foreach {write-host $_.node.InnerXML}
  </code></pre>