0
我正在編寫一個搜索網絡位置的Powershell腳本,並且如果該文件是在2011或2012年創建的,然後將文件名寫入日誌以及所有2011/12的總和創建的文件。使用_.LastWriteTime轉換日期的問題
我收到了一個異常,它試圖轉換文件創建的日期和時間並將其與我的日期範圍進行比較。
<#Checks one network location for files from 2011.
gets the name of that file and adds to the count for 2011, then writes it to a log.
Repeats for 2012.#>
New-Item c:\users\logs\yearLog.txt -type file -force
$path = "\\path"
$log = "c:\users\log"
$date2011 = "2011"
$date2012 = "2012"
write-progress -activity "Compiling Data" -status "Progress:"
$x = 0
"$date2011 files" | add-content $log
Get-Childitem -Path $path -Recurse | Where-Object {$_.LastWriteTime -gt (12/31/2010) -AND $_LastWriteTime -lt (01/01/2012) |
ForEach {
$filename = $_.fullname
$x++
"$filename" | add-content $movelog
}
"$date2011 total files = $x" | add-content $log
$x = 0
"$date2012 files" | add-content $log
Get-Childitem -Path $path -Recurse | Where-Object {$_.LastWriteTime -gt (12/31/2011) -AND $_LastWriteTime -lt (01/01/2013) |
ForEach {
$filename = $_.fullname
$x++
"$filename" | add-content $log
}
"$date2012 total files = $x" | add-content $log
}
}
用引號括起日期:*「12/31/2010」*。否則它會嘗試將12除以31,然後再減去2010。 –
謝謝zespri。我應該抓到那個:)顯然,這不是我唯一的問題 –
請發送例外文本請 –