简体   繁体   English

PowerShell v2.0 SQLPS如果“天数”大于#

[英]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. 我正在使用PowerShell脚本从SQL Server 2008 R2查询生成HTML报告。 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. 我的目标是将90天之前的日期标记为黄色。

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. 我在SQLPS中收到错误:无效的赋值表达式。 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. 给变量加上[datetime]前缀,使用New-TimeSpan,也没有.Days。 Please let me know if this is possible. 如果可以的话,请告诉我。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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