爲什麼ELSE在以下工作?語法和流程似乎對條件是正確的。請不要發佈備用解決方案,而不必解釋下面的邏輯不起作用的原因。理想情況下,最不復雜的例子(這是人類可讀的)將非常感激。嵌套的IF ELSE條件和邏輯因某種原因不起作用
電流輸出
文件存在*
預期輸出:
文件存在!
這種情況也是如此。但被腳本忽略!
無論出於何種原因,「ELSE」行不執行下面...... 雖然香港專業教育學院已經證實,$文件存在,$ FileLeaseGood = $空
的我的方式閱讀我的腳本,「ELSE」特定於$ FileLeaseGood IF語句,而不是$ File exists IF語句。
$File = gi "P:\tmp\MKA.theme"
$lastWrite = (get-item $File).LastWriteTime
$timespan = new-timespan -hours 8
$FileLeaseGood = $NULL
if (((get-date) - $lastWrite) -le $timespan) {$FileLeaseGood = $True}
if (Test-Path $File) {
write-host "File exists!"
if ($FileLeaseGood) {
write-host "File exists! and File Lease still good"
}} else {
#Why doesn't this else condition work???
Write-host "This condition is also true. But ignored by script!"
}
運行此操作後,您的輸出是什麼?哪個寫主機會執行? – rageit
'write-host'!='寫主機'? –
他們的方式這是編碼,如果該文件不存在「的條件是真的」。這只是支架放置問題。 – Matt