【发布时间】:2021-11-21 10:54:15
【问题描述】:
今天 (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"
}
即使两天之差是 39,我的代码也会在 if 子句中跳转并将“test”发送到屏幕。
我在这里做错了什么?
【问题讨论】:
标签: powershell syntax operators equality-operator