我正在编写一个搜索网络位置的 Powershell 脚本,如果文件是在 2011 年或 2012 年创建的,则将文件名以及创建的所有 2011/12 文件的总和写入日志。
当它尝试转换文件创建的日期和时间并将其与我的日期范围进行比较时,我遇到了异常。
<#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
}
}