Powershellers,
I am a SQL Dba and am creating some powershell scripts. I usually use invoke-sqlcmd without major issues.
I have come accross an issue with date precision. The stored procedures ‘absolutly’ return a value like '2021-09-20 10:35:00.643. Invoke-sqlcmd will not. It rounds to 10:35:01. I am not able to show you the stored procedure but can mimik the scenario thru manual input in my example. To test the invok-sqlcmd you would of course need to supply your own cridential to some sql instance. The $datetest variable shows that Poweshell IS showing the full value. Is there some global setting that forces this to show the precision to milliseconds? The constraint is that I am NOT going to change the logic in the sp for dateformatting - those run fine
param(
[string]$IN_SQLQuery = "Select convert(datetime,'2021-09-20 10:35:00.643') as BatchRunDateTime"
)
[datetime] $datetest
$datetest = '2021-09-20 10:35:00.643'
$datetest
$results = @(Invoke-Sqlcmd -ServerInstance $SQLServerNameConnection -Database $dbname -Username $UserName -Password $Password -Query $IN_SQLQuery -QueryTimeout 600 -AbortOnError )
foreach($result in $results)
{
$result[0]
}