My SQLite database contains a nullable DateTime field that I have to read in PowerShell. My select
query:
$colId = "myPrimaryKeyColumn"
$col1 = "myColumnName"
$select = "SELECT CAST($col1 as nvarchar(20)) FROM $table ORDER BY $colId DESC LIMIT 1"
Which returns CAST(Alive as nvarchar(20)) : 04/11/2022 17:17:15
. How to get just the 04/11/2022 17:17:15
part?
I tried :
Invoke-SqliteQuery -SQLiteConnection $con -Query $select | Where-Object { $_.$col1}
Invoke-SqliteQuery -SQLiteConnection $con -Query $select -As DataRow | Where-Object { $_.$col1}
Invoke-SqliteQuery -SQLiteConnection $con -Query $select -As PSObject| Where-Object { $_.$col1}
Which prints just an empty line.
CodePudding user response:
You need to use -As SingleValue
(you don't need Where-Object
)
Invoke-SqliteQuery -SQLiteConnection $con -Query $select -As SingleValue