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。我应该抓到那个:)显然,这不是我唯一的问题 –
请发送例外文本请 –