極端的PowerShell新手在這裏。我感謝任何和所有的幫助。 我正在嘗試將一個簡單的防洪腳本放在一起,以便與Sharepoint/Powershell一起使用。需要查看字段中的日期時間並將其與當前日期時間進行比較,然後在最後提交的5秒內停止執行。現在使用的方法似乎總是評估爲真。Powershell/Sharepoint反洪泛腳本
#get system datetime (output format - 06/12/2014 07:57:25)
$a = (Get-Date)
# Get current List Item
$ListItem = $List.GetItemById($ItemID)
$DateToCompare = $ListItem["baseline"].AddMilliseconds(5000)
if ($DateToCompare -gt $a)
{Break}
#set variable to field
$ListItem["baseline"] = $a
#write new item
$ListItem.Update()
Break
這是發生在循環內嗎?那些斷言陳述脫離了上下文。 – mjolinor
否定的。如果IF語句的計算結果爲false,則會發生寫入操作。 – user3723688
中斷旨在用於循環或開關結構中。除此之外,我會使用Return來代替。 – mjolinor