我正在嘗試接收每個排序步驟的詳細訊息并使用-Verbose鍵運行我的腳本,但我沒有收到來自條件(回圈)的任何詳細訊息。只有當我在條件之外呼叫它們時,我才會收到我的訊息。請幫忙
[CmdletBinding()]
param()
set-location "\test folder"
$listOfItems = Get-ChildItem | Select-Object -Property Name, Mode, LastWriteTime, @{label = "FileSize (MB)";expression = {$_.Length/1024/1024}}
$bufferItem = 0
for ($i = $listOfItems.Length - 1; $i -eq 0; $i--) {
for ($j = 0; $i -lt $i; $j ) {
if ($listOfItems[$j]."FileSize (MB)" -gt $listOfItems[$j 1]."FileSize (MB)") {
Write-Verbose -Message "Transfer the value of the buffer variable to the element below the list"
continue
}
elseif ($listOfItems[$j]."FileSize (MB)" -lt $listOfItems[$j 1]."FileSize (MB)") {
$bufferItem = $listOfItems[$j]
$listOfItems[$j] = $listOfItems[$j 1]
$listOfItems[$j 1] = $bufferItem
}
Write-Verbose -Message "Transfer the value of the buffer variable to the element below the list"
}
}
uj5u.com熱心網友回復:
您的內部回圈條件存在錯誤:
for ($j = 0; $i -lt $i; $j ) {
由于$i -lt $i永遠不會對 求值$true,因此內部回圈體永遠不會執行,Write-Verbose也不會到達任何陳述句。
修復回圈條件,你會發現Write-Verbose在條件陳述句中作業得很好。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/345226.html
上一篇:如何在保持當前作業目錄并維護傳遞給腳本的所有引數的同時提升Powershell?
下一篇:在SSIS.dtsx包中查找表名
