简体   繁体   中英

PowerShell v2.0 SQLPS If Days between are greater than #

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.

if ($var=([datetime](Get-Date) - [datetime]$_.'Oldest Work Date').Days -gt 90)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM