DateTime减法在PowerShell中不起作用 - 赋值与等于运算符

Joe*_*oey 2 syntax powershell operators

今天(2017-05-29)我在Windows 7 Enterprise上使用PowerShell 5.0.10586.117并运行以下(缩短版):

$dateOfLicense = "2017-04-20"
$dateOfToday = '{0:yyyy-MM-dd}' -f (Get-Date)

$TimeDifference = [DateTime]$dateOfToday - [DateTime]$dateOfLicense 
if (($TimeDifference) = 14)
{
    Write-Host "test"
}
Run Code Online (Sandbox Code Playgroud)

即使两天之间的差异是39,我的代码跳转到if子句并将"test"发送到屏幕.

我在这做错了什么?

Mar*_*ndl 6

你要分配 14$TimeDifference.相反,你不想Days使用-le以下方法比较财产:

if ($TimeDifference.Days -le 14)
{
    Write-Host "test"
}
Run Code Online (Sandbox Code Playgroud)