我正在尝试从sql列中存储的xml中获取第一个节点值。目前,它显示了所有的UniqueID,但是我只想要第一个,即+ 7f8wMRJgFKWlQqyWwI27yOVc80 =
XML :
<UniqueIDList>
<UniqueID>+7f8wMRJgFKWlQqyWwI27yOVc80=</UniqueID>
<UniqueID>3LZYc365TRSHEUZRwBaaYCPszqQ=</UniqueID>
<UniqueID>WnK4aLZKO8kFyi+Ii8s9A2yl/Kg=</UniqueID>
<UniqueID>i0UHoU0r2fYBvCrvFbcKkikXgas=</UniqueID>
</UniqueIDList>
Powershell代码:
$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}