I am working on a PowerShell script to generate a HTML report from a SQL Server 2008 R2 query. The current script shows as:
$Date = Get-Date
$Summary = Invoke-SQLcmd -Query $Qry | Select-Object -Property 'Oldest Work Date'
$Summary | ForEach-Object {
if (($Date - $var=$_.'Oldest Work Date').Days -gt 90)
{
{
$data+=
"<tr bgcolor = `"yellow`">
<td>$($_.'Oldest Work Date')</td>
</tr>"
}
else
{
$data+=
"<tr>
<td>$($_.'Oldest Work Date')</td>
</tr>"
}
}
My goal is to markup the dates greater than 90 days ago with the row highlighted in yellow.
I am having trouble with the expression-
(($Date - $var=$_.'Oldest Work Date').Days -gt 90)
I am receiving the error in SQLPS: Invalid assignment expression. The left hand side of an assignment operator needs to be something that can be assigned to a variable or a property.
I have searched and tried many different versions. Ie. prefixing the variables with [datetime], used New-TimeSpan, and also without the .Days. Please let me know if this is possible.